Fix --help/--wizard showing wrong subcommand help (#448) — review follow-up#576
Merged
Merged
Conversation
6a309ad to
068911b
Compare
Address review feedback on zio#559: - Extract the duplicated ValidationError into a local val. - Replace the if/else in parseBuiltInArgs with ZIO#collect, which matches the style used in Subcommands#parse and folds the Some(value)/leftover.isEmpty success and the failure into a single partial function. - Add a regression test covering the leftover.nonEmpty branch directly: 'cmd --help payload' must not be consumed as a built-in directive. Co-authored-by: Thomas Järvstrand <tjarvstrand@gmail.com>
Both helpDirectiveForChild and wizardDirectiveForChild constructed the same conf.copy(finalCheckBuiltIn = false) and the same ValidationError(InvalidArgument, HelpDoc.empty). Hoist them to shared local vals to keep the two branches in lockstep. Co-authored-by: Thomas Järvstrand <tjarvstrand@gmail.com>
068911b to
b75c735
Compare
Contributor
|
Sorry for dropping the ball on this! Thanks for picking it up! |
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.
Continues #559 by @tjarvstrand. The original fix is unchanged; this PR adds the refactor requested in the review thread (#559 (comment)) plus closely-related cleanups, so credit for the fix stays with the original author.
Commits
eb68646(tjarvstrand) — original fix for Built in args like --help in Subcommand was unexpected behavior #448, unchanged.NoBuiltInMatcherror and cover leftover case — addresses the review feedback onparseBuiltInArgs:if (leftover.nonEmpty) ... else ZIO.fromOption(value).mapError(...)withZIO#collect(noBuiltInMatch) { case (_, Nil, Some(value)) => CommandDirective.BuiltIn(value) }, matching the style already used inSubcommands#parse. Also folds the.map(BuiltIn)step into the partial function.sinterpolator on the error message (per the original Copilot note).noBuiltInMatchasdefrather thanval. Both consumers (ZIO#collect'se: => E1andZIO.fail'serror: => E) take their failure by-name, sodefdefers allocation to the failure path while keeping the descriptive name.leftover.nonEmptybranch (cmd --help payloadandcmd --wizard payloadmust not be consumed as built-in directives). The--helpvariant was first verified RED onmaster(returned"help"instead of"user") before being committed.childConfandinvalidArgumentinSubcommands.parse— bothhelpDirectiveForChildandwizardDirectiveForChildconstructed the sameconf.copy(finalCheckBuiltIn = false)and the sameValidationError(InvalidArgument, HelpDoc.empty). Hoisted to shared local definitions to keep the two branches in lockstep.invalidArgumentisdeffor the same by-name reason as above;childConfstaysvalsincechild.parsetakes its config strictly.Behavior
Pure refactor — no behavior change.
zioCliJVM/testOnly zio.cli.CommandSpeczioCliJS/testOnly zio.cli.CommandSpeczioCliNative/testOnly zio.cli.CommandSpecscalafmtCheckAllCloses #448 if merged.