diff --git a/crates/nu-command/tests/commands/def.rs b/crates/nu-command/tests/commands/def.rs index d866419e1c..c8371753a9 100644 --- a/crates/nu-command/tests/commands/def.rs +++ b/crates/nu-command/tests/commands/def.rs @@ -1,5 +1,5 @@ -use nu_test_support::nu; use nu_test_support::playground::Playground; +use nu_test_support::{nu, pipeline}; use std::fs; #[test] @@ -18,3 +18,15 @@ def e [arg] {echo $arg} assert!(actual.out.contains("My echo\\n\\n")); }); } + +#[test] +fn def_errors_with_multiple_short_flags() { + let actual = nu!( + cwd: ".", pipeline( + r#" + def test-command [ --long(-l)(-o) ] {} + "# + )); + + assert!(actual.err.contains("expected one short flag")); +} diff --git a/crates/nu-parser/src/parser.rs b/crates/nu-parser/src/parser.rs index 941ea396b1..46c842beba 100644 --- a/crates/nu-parser/src/parser.rs +++ b/crates/nu-parser/src/parser.rs @@ -3126,6 +3126,10 @@ pub fn parse_signature_helper( var_id: Some(var_id), default_value: None, })); + } else if flags.len() >= 3 { + error = error.or_else(|| { + Some(ParseError::Expected("one short flag".into(), span)) + }); } else { let short_flag = &flags[1]; let short_flag = if !short_flag.starts_with(b"-")