fix(cli): accept --format after a subcommand - #6464
Open
sanjay3290 wants to merge 1 commit into
Open
Conversation
Add global=true to the format arg so --format parses after a subcommand as well as before it. Fixes block#6391 Signed-off-by: Sanjay Ramadugu <sramadugu1@gmail.com> Co-authored-by: Sanjay Ramadugu <sramadugu1@gmail.com>
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.
Problem
Fixes #6391.
--formatis declared on the top-levelClistruct withoutglobal = true, so clap only accepts it before the subcommand:The second form is what people actually type, and it is how every other CLI treats an output-format flag.
Change
One line: add
global = trueto theformatarg.OutputFormatalso gainsDebugandPartialEqso the tests can assert on it.Tests
Three tests in the existing
mod tests, all driving the realCliparser viaCli::try_parse_from, not a synthetic command:format_after_subcommand_parses— the previously broken form; fails onmainwith an unexpected-argument error.format_before_subcommand_parses— the form that already worked, so the fix does not trade one position for the other.format_defaults_to_json— the default survives.Deletion probe: removing
global = truemakesformat_after_subcommand_parsesfail.Verification