fix(cli): stop activating scenarios for help and version output - #187
Merged
Conversation
Activation ran before the command line was parsed, so an unloadable binding in session.json printed a warning ahead of ivicli --version and broke anything reading that output.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ivicli --versioncould print this first:Anything reading the version out of that output gets the warning line. Noticed while installing through mise, where the surrounding tooling made it obvious.
Cause
ActivateScenarioIfRequestedran beforeroot.Parse(args). The comment explaining why — "so visa subcommands see the scenario on this same invocation" — is a good reason to activate early, but not a reason to activate before knowing what the invocation is.--version,--help, and a command line that does not parse never open a session, so reading the scenario store for them buys nothing and can only add noise.Fix
Parse first, then decide. Parsing has no side effects, and the resulting
ParseResultis invoked directly afterwards rather than re-parsed.ScenarioActivation.IsNeededForasks the parser what it resolved rather than matching raw tokens:Action is HelpActioncovers--helpat every level, aVersionOptionresult covers--version(its action type is not public, so the option is the handle), andErrors.Count > 0covers a line that will not run. An argument that merely looks like--versiontherefore still activates — pinned by a test.Also correct, and worth noting because it surprised me while writing the test: a bare group such as
ivicli visaprints its own help, so it resolves toHelpActionand skips activation too.Evidence
Not just "the warning is gone" — that could mean activation broke everywhere. With the same planted
session.jsonnaming a scenario that does not exist:Nine unit tests over the predicate, mutation-checked: removing the
HelpActionbranch fails four of them. Full CLI suite 125/125.