-
Notifications
You must be signed in to change notification settings - Fork 8
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
fix: Posix compliant argument parsing for -c
mode
#147
Conversation
I haven't write integration tests yet. Are test cases compare its output to the bash equivalent? |
Performance Benchmark Report
Code Coverage Report: Only Changed Files listed
Minimum allowed coverage is |
Thanks for contributing! I'd like to find a few minutes to read through your changes to make sure I understand them, but it looks like a good find. There's a (very) minimal write-up on the integration tests under docs/reference but the full schema of the .yaml case files still needs to be properly documented. As you called out, the test cases are run under bash and brush with exit code, stderr, and stdout compared. There's also some options for specifying command-line arguments to the shell, ignoring stderr differences, etc. The existing test cases are the best examples. If the test case schema isn't sufficiently expressive to handle a new case, we can always change the test harness to support more options. |
I will write test cases today soon |
Tests for argument handling are ready. I've created a new file While testing I found another bug/difference with bash. I think it is also related to clap # bash
echo -- 1
#> -- -1
# brush
echo -- -1
#> -1 |
@39555 thanks for adding test coverage! For each new bug we find, I'd very much like us to follow that pattern to ensure the fix doesn't regress. As for the other case you mention ( Given that we're now seeing this in multiple places, do you think there's a more general fix or at least some common helper function/code we should extract to solve this problem across built-ins and brush's command line? |
I found an opened issue in clap clap-rs/clap#5055. Maybe we could resolve it. |
Good to know that In the meantime, I'm supportive of moving forward with a fix for this issue and filing a separate issue on Regarding the actual code change here, would you please factor out the parsing logic that you've updated into a separate helper function? I think that will at least help to contain the workaround. Thanks! |
@reubeno To which module can I place such a function? |
@39555 Sorry, I wasn't very clear. For now, I was just thinking of extracting a helper function in the same |
3fb9c65
to
ff2cdc3
Compare
I meant that I've already tried it in
What do you think? |
Ah! Thanks for clarifying and continuing to work on it. I'll look more closely at your latest rev. |
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.
Thanks for making these changes! (And apologies for taking so long to get back to you.) Hopefully we'll be able to remove the workaround in the future if clap-rs adds support for this case...
Hi @39555 -- are you still willing and interested to help get these changes in? |
- clap does not handle `--` as an argument but rather as a separator so we need additional processing for passing `--` as an operand to a `-c` script. This is because Posix interprets `--` as an operand. The first argument in `-c` is the name of the command and can be `--` just fine. See: Posix about sh https://pubs.opengroup.org/onlinepubs/9699919799/utilities/sh.html https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html#tag_12_02 test: tests for command line argument handling feat: helper functions to deal with clap's limitation handling `--` - Added functions `try_parse_known` and `parse_known` for splitting arguments into `before hyphen` and `hyphen and after hyphen` - This approach allows manually deciding what to do with `--` and the remaining arguments Fixes: - main CommandLineArgs - EchoCommand Clap issue: clap-rs/clap#5055 fix: clippy lints
587eb60
to
6627893
Compare
Hi! Sorry! I've rebased onto the main and updated my branch |
Looks like the |
5b1effb
to
f7a9439
Compare
All done |
Thanks for the quick turnaround! Looks like all checks are passing fine. I'll complete the PR shortly. I plan to create a new release sometime this week and would like to include this fix in it. Thanks again for your contribution 🙂 |
Before
Brush misses
--
because of clap's approach to argument parsing. See: clap-rs/clap/clap_builder/src/parser/parser.rsif arg_os.is_escape() { ...; continue } // means arg_os == '--'
and--
is skipped.But Posix can handle
--
as an operand or a command_name just fine.After This PR