-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
echo: fixed double hyphen as argument #7581
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
Conversation
GNU testsuite comparison:
|
src/uu/echo/src/echo.rs
Outdated
for arg in args { | ||
if arg == "--" && is_first_double_hyphen { | ||
for (i, arg) in args.enumerate() { | ||
if arg == "--" && i == 1 { |
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.
please add a comment to explain what is it
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.
added a comment
seems that it regressed upstream tests |
…f at start of arguments to correctly prepend addition hyphens for clap as well as additional test case
i rebased main and pushed a comment ... on my machine no tests are failing i hope the error was that i hadnt rebased main into my fork before pushing (?) |
GNU testsuite comparison:
|
This seems to have the same bug as my PR (#7559): $ cargo run -q echo -n -e -- 'foo\n'
foo The double hyphen gets eaten up if it is given immediately after a flag that is recognized by Clap. Solving this problem could be less straightforward than it seems... :( |
a357dce
to
ece6492
Compare
There's a limitation in your fix in a8d6780: # doesn't work with combined flags
$ cargo run -q echo -eE -- hi
hi |
mhh ... i could modify the is_echo_flag to manually go through the given string and check if index 0 is '-' and then any following char is either 'e' 'E' 'n' would this be too much of code or acceptable? i see that with the gnu echo you can even give as an input flags such as '-nneE' which doesnt work as clap will throw an error should i already limit checks at index 4 t hen as multiple flags are not allowed and will be caught later by clap or ignore that? |
i also discovered that |
GNU testsuite comparison:
|
POSIX says to not apply any of the normal options processing and only check if the first arg is -n: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/echo.html GNU is more complicated but I think the same principle applies: we shouldn't use clap to parse at all. Maybe we can use it to generate the help message but we need very simple parsing so we're better off doing it ourselves instead of trying to coerce clap.
Like that, and then you can manually set |
Won't work with cases such as
This is probably why the best approach is to just not use clap at all for implementing echo. It seems to be complicating things a whole lot.
Yeah, makes sense to do that. |
I would suggest that i fix the problem at hand and removing clap would be a new issue all together? i found even more cases where flags are printed improperly compared to gnu coreutils
tip: to pass '-g' as a value, use '-- -g' Usage: cargo run [OPTIONS] [ARGS]... For more information, try '--help'. |
Huh, which version of echo are you on? For me it prints the $ /bin/echo - -neE
- -neE
$ /bin/echo --version
echo (GNU coreutils) 8.32
I think the trick here is to use If in doubt you can also check with
That makes sense. |
Thanks for your work on this issue, @cerdelen and @Expertcoderz ! |
* Fixes uutils#7558 Added check to only insert addition double hyphen if at start of arguments to correctly prepend addition hyphens for clap as well as additional test case * additional comment * fixes issue where flags precedes "--" as arguments
Added check to only insert addition double hyphen if at start of arguments to correctly prepend addition hyphens for clap as well as additional test case