mirror of
https://github.com/nushell/nushell
synced 2024-12-26 13:03:07 +00:00
Restrict short-hand flag detection to exact match. (#1406)
This commit is contained in:
parent
0f7c723672
commit
18d988d4c8
2 changed files with 30 additions and 2 deletions
|
@ -368,8 +368,13 @@ impl SpannedToken {
|
||||||
|
|
||||||
match flag.kind {
|
match flag.kind {
|
||||||
FlagKind::Longhand if value == name => Some(*flag),
|
FlagKind::Longhand if value == name => Some(*flag),
|
||||||
FlagKind::Shorthand if short.is_some() && short == name.chars().next() => {
|
FlagKind::Shorthand => {
|
||||||
Some(*flag)
|
if let Some(short_hand) = short {
|
||||||
|
if short_hand.to_string() == name {
|
||||||
|
return Some(*flag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,6 +56,29 @@ mod parse {
|
||||||
-r, --raw: Prints the raw value representation.
|
-r, --raw: Prints the raw value representation.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn errors_if_flag_passed_is_not_exact() {
|
||||||
|
let actual = nu_error!(cwd: ".", "debug -ra");
|
||||||
|
|
||||||
|
assert!(
|
||||||
|
actual.contains("unexpected flag"),
|
||||||
|
format!(
|
||||||
|
"error message '{}' should contain 'unexpected flag'",
|
||||||
|
actual
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
let actual = nu_error!(cwd: ".", "debug --rawx");
|
||||||
|
|
||||||
|
assert!(
|
||||||
|
actual.contains("unexpected flag"),
|
||||||
|
format!(
|
||||||
|
"error message '{}' should contain 'unexpected flag'",
|
||||||
|
actual
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn errors_if_flag_is_not_supported() {
|
fn errors_if_flag_is_not_supported() {
|
||||||
let actual = nu_error!(cwd: ".", "debug --ferris");
|
let actual = nu_error!(cwd: ".", "debug --ferris");
|
||||||
|
|
Loading…
Reference in a new issue