-
Notifications
You must be signed in to change notification settings - Fork 312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cli: insert dummy -h/--help flag when parsing early args #4755
base: main
Are you sure you want to change the base?
Conversation
Since 536c629 "cli: Explicitly add a Help command to accept the early args after it", "jj help" is a normal subcommand.
@@ -559,6 +559,16 @@ fn test_early_args() { | |||
let stdout = test_env.jj_cmd_success(test_env.env_root(), &["help", "--color=always"]); | |||
insta::assert_snapshot!(stdout.lines().find(|l| l.contains("Commands:")).unwrap(), @"[1m[4mCommands:[0m"); | |||
|
|||
// Check that early args are accepted after -h/--help |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Optional) Should we also test --color=always -h
?Or is that completely equivalent to --color=always --help
? (Or is it tested somewhere else?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They're equivalent in implementation wise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much! This looks good to me, I'll also ping @Grillo-0 in case they have any thoughts.
@@ -3032,8 +3032,15 @@ fn handle_early_args( | |||
let early_matches = app | |||
.clone() | |||
.disable_version_flag(true) | |||
// Ignore any appearance of -h/--help and continue parsing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Non-blocking) I am a bit confused about why this works (Update: or, to be more precise, why it didn't work before). Shouldn't .disable_help_flag(true).ignore_errors(true)
have been sufficient to ignore -h
while parsing?
Depending on the answer, it might be nice to add it to the comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In clap, help is an "error" (or a thing that triggers exceptional code path.) That's my understanding.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, but shouldn't ignore_errors
ignore this error, especially since the help flag is disabled? I guess it clearly doesn't. Maybe it's a documentation bug in clap.
Thanks again for figuring it out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the comment should be moved to the next line and say (if this is true):
Without this, parsing will stop on the first
-h
or--help
, despite .disable_help_flag() and .ignore_errors().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, but shouldn't ignore_errors ignore this error, especially since the help flag is disabled?
If the default -h
is disabled, -h
triggers a normal parse error. If it's enabled, -h
triggers a "help requested error". In both cases, any remaining args won't be parsed. We do need to skip over -h
. And that's why I put the comment there.
#4746
Checklist
If applicable:
CHANGELOG.md