Repository navigation
env: only suggest -S when an argument contains a space - #16712
shivangithaker-0510 wants to merge 2 commits into
Conversation
The 'use -[v]S to pass options in shebang lines' hint was printed for every missing program and after every option error. Print it only when the missing program or the rejected option contains a space, which is when a whole shebang line was passed as one argument, like GNU env. Closes uutils#16423
| let show_shebang_hint = matches!( | ||
| e.get(clap::error::ContextKind::InvalidArg), | ||
| Some(clap::error::ContextValue::String(arg)) | ||
| if looks_like_shebang_line(arg.as_bytes()) |
There was a problem hiding this comment.
this only works for -v -S cat -n because clap reports - as the invalid arg, no?
checking the raw argument would be more robust
| .stderr_does_not_contain(hint); | ||
| new_ucmd!() | ||
| .args(&["-v", "-x y"]) | ||
| .fails_with_code(125) |
There was a problem hiding this comment.
are you sure GNU doesn't print the hint for -x y? could you please check it?
| /// line such as `cat -n` was passed as a single argument. Only then is the | ||
| /// hint to use `-S` worth printing. | ||
| fn looks_like_shebang_line(arg: &[u8]) -> bool { | ||
| arg.contains(&b' ') |
There was a problem hiding this comment.
what about tabs? the issue says whitespace
|
GNU testsuite comparison: |
…whitespace option
Match GNU env: the hint is shown when a missing program name contains
whitespace (space, tab, newline, vertical tab, form feed or carriage
return), or when the rejected short option is itself a whitespace
character, as for '-v -S cat -n'. An unknown option that merely contains
whitespace ('-x y', '--foo bar') does not get the hint.
Merging this PR will regress 1 benchmark3 warnings
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
The 'use -[v]S to pass options in shebang lines' hint was printed for every missing program and after every option error. Print it only when the missing program or the rejected option contains a space, which is when a whole shebang line was passed as one argument, like GNU env.
Closes #16423