Allow arguments for the last flag in short flag batch #8808
Allow arguments for the last flag in short flag batch #8808sholderbach merged 4 commits intonushell:mainfrom
Conversation
|
👋 quite strangely, it does already work with i have alias.cm=commit --verboseand git cm -am "foo"works 😕 |
@amtoine Very interesting, I have some of the aliases from In fact, could you further explain (or point me to the right docs) what |
oooh i see what you're using 😋
i should have been clearer, sorry 😢
|
Oh my no worries at all! I was confused because I thought you were talking about |
crates/nu-parser/src/parser.rs
Outdated
| orig.start + 1 + short_flag.0, | ||
| orig.start + 1 + short_flag.0 + 1, | ||
| ); | ||
| let short_flag_span = Span::new(orig.start + 1 + i, orig.start + 1 + i + 1); |
There was a problem hiding this comment.
This line previously already made the assumption that a short flag is only an ASCII character and requires just one byte. Our parsing of definitions apparently doesn't check for that causing downstream panics. I opened an issue for that (#8821)
There was a problem hiding this comment.
@sholderbach would you like #8821 to get fixed first, or are you okay with merging this before?
There was a problem hiding this comment.
nvm, it seems like #8849 fixed the issue!
2393d2e to
101404f
Compare
101404f to
48af0eb
Compare
Run cargo fmt Update tests to new short batch parsing
48af0eb to
3b55612
Compare
|
I've updated the PR to accommodate for the latest changes from #8849 :) |
# Description Follow up to #8849 Work for #8821 Should unblock work on #8808 Missing is a restriction to printables or identifiers according to [UAX31](https://www.unicode.org/reports/tr31/) # User-Facing Changes Non ASCII characters should be allowed in shortflags. # Tests + Formatting Want to add some tests for the error reporting cases
- Include the span fixes from nushell#8866 - Include the `break;` back in - Remove unnecessary clone
sholderbach
left a comment
There was a problem hiding this comment.
The implementation and your tests look good to me. Thank you very much!
Should be easy to update to the state of #8866
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #8808 +/- ##
=======================================
Coverage 68.51% 68.51%
=======================================
Files 636 636
Lines 101657 101657
=======================================
+ Hits 69647 69648 +1
+ Misses 32010 32009 -1
|
|
@sholderbach For my own learning: Could you please explain what the 88.88% diff coverage refers to in the comment above? I'm reading the Codecov docs and all the other values in the summary table make sense to me, but I'm not understanding where that 88.88% is coming from... |
| let mut found_short_flags = vec![]; | ||
| let mut unmatched_short_flags = vec![]; | ||
| for (offset, short_flag) in short_flags.char_indices() { | ||
| let orig = arg_span; |
There was a problem hiding this comment.
There's no need to keep orig.
I think it is the fraction of the added or changed lines that are measured to be covered. But the exact numbers can be weird depending on pure definitions or test modules |
# Description Follow up to nushell#8849 Work for nushell#8821 Should unblock work on nushell#8808 Missing is a restriction to printables or identifiers according to [UAX31](https://www.unicode.org/reports/tr31/) # User-Facing Changes Non ASCII characters should be allowed in shortflags. # Tests + Formatting Want to add some tests for the error reporting cases
# Description _Fixes #5923_ Currently `nushell` doesn't allow short flag batches to contain arguments, despite this being a common pattern in commands like `git commit -am 'My commit message'`. This PR relaxes this so that the last flag in the batch can take an argument. # User-Facing Changes - `nu::parser::short_flag_arg_cant_take_arg` has been replaced by `nu::parser::only_last_flag_in_batch_can_take_arg` and is displayed when a flag other then the last in a short flag batch takes an argument. # Tests + Formatting - Both [`test_parser.rs`](https://github.com/nushell/nushell/blob/48af0ebc3c9f0c7b0ef134078fe1a0e47982059e/crates/nu-parser/tests/test_parser.rs#L640-L704) and [`test_known_external.rs`](https://github.com/nushell/nushell/blob/48af0ebc3c9f0c7b0ef134078fe1a0e47982059e/src/tests/test_known_external.rs#L42-L61) have been updated to test the new allowed and disallowed scenarios. --------- Co-authored-by: sholderbach <sholderbach@users.noreply.github.com>
I still don't get it but all the diffs are green so I'm happy with that 😅 |
Me neither 😆 |
Description
Fixes #5923
Currently
nushelldoesn't allow short flag batches to contain arguments, despite this being a common pattern in commands likegit commit -am 'My commit message'. This PR relaxes this so that the last flag in the batch can take an argument.User-Facing Changes
nu::parser::short_flag_arg_cant_take_arghas been replaced bynu::parser::only_last_flag_in_batch_can_take_argand is displayed when a flag other then the last in a short flag batch takes an argument.Tests + Formatting
test_parser.rsandtest_known_external.rshave been updated to test the new allowed and disallowed scenarios.