Repository navigation
Allow arguments for the last flag in short flag batch - #8808
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 |
| 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 <[email protected]>
I still don't get it but all the diffs are green so I'm happy with that 😅 |
Me neither 😆 |
…19642) ## Description `generate completions cargo` declares `-Z: string`, and with that extern loaded, `cargo -Zscript foo.rs` failed with `only_last_flag_in_batch_can_take_arg`. `^cargo -Zscript` and `cargo -Z script` both worked. `make -j8` and `git commit -amf` failed the same way under their externs. `git commit -amf` is the example in #5923, which #8808 closed by letting the last flag in a batch take the next word. The attached form never worked. A known external now reads short flags the way `getopt` does. When a flag that takes a value comes before the end of the word, the rest of the word is its value, and the word goes to the program as written. Nushell still checks that value against the flag's type, so `-jabc` with `-j: int` fails like `-j abc` does. `extern --strict` accepts the word when every flag in it is declared. Nushell commands and `def --wrapped` keep the old rule. ```nushell > cargo -Zscript fp_asm.rs # before Error: nu::parser::only_last_flag_in_batch_can_take_arg × Only the last flag in a short flag batch can take an argument. ╭─[source:1:37] 1 │ source cargo_completions.nu; cargo -Zscript fp_asm.rs | complete | reject stdout · ┬ · ╰── only the last flag can take args > cargo -Zscript fp_asm.rs # after, on stable cargo error: the `-Z` flag is only accepted on the nightly channel of Cargo, but this is the `stable` channel ``` ## User-facing changes (Release notes) Commands declared with `extern` accept a short flag with its value attached, such as `cargo -Zscript`, `make -j8` or `git commit -amf`, and pass it to the program as written. ## Additional notes closes #19639 - Values that start with `$` or `(` skip the type check. Inside the word, `-Z$x` stays literal and `-Z(1 + 2)` becomes `-Z3`, so checking `$x` or `(1 + 2)` alone would test something the program never gets. - The last-flag check also had a bug. It compared a byte offset with a character count, so in `-éjm 5` the `-j` took a value without being last. It now compares spans.
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.