diff --git a/crates/nu-parser/src/parser.rs b/crates/nu-parser/src/parser.rs index 47c631b68ae58..cf30f46c24627 100644 --- a/crates/nu-parser/src/parser.rs +++ b/crates/nu-parser/src/parser.rs @@ -401,13 +401,31 @@ fn parse_long_flag( } } else { // A flag with no argument - ( - Some(Spanned { - item: long_name, - span: arg_span, - }), - None, - ) + // It can also takes a boolean value like --x=true + if split.len() > 1 { + // and we also have the argument + let long_name_len = long_name.len(); + let mut span = arg_span; + span.start += long_name_len + 3; //offset by long flag and '=' + + let arg = parse_value(working_set, span, &SyntaxShape::Boolean); + + ( + Some(Spanned { + item: long_name, + span: Span::new(arg_span.start, arg_span.start + long_name_len + 2), + }), + Some(arg), + ) + } else { + ( + Some(Spanned { + item: long_name, + span: arg_span, + }), + None, + ) + } } } else { working_set.error(ParseError::UnknownFlag( diff --git a/src/tests/test_custom_commands.rs b/src/tests/test_custom_commands.rs index f9daa5c543718..3447d80f11999 100644 --- a/src/tests/test_custom_commands.rs +++ b/src/tests/test_custom_commands.rs @@ -83,6 +83,35 @@ fn custom_switch2() -> TestResult { #[test] fn custom_switch3() -> TestResult { + run_test( + r#"def florb [ --dry-run ] { $dry_run }; florb --dry-run=false"#, + "false", + ) +} + +#[test] +fn custom_switch4() -> TestResult { + run_test( + r#"def florb [ --dry-run ] { $dry_run }; florb --dry-run=true"#, + "true", + ) +} + +#[test] +fn custom_switch5() -> TestResult { + run_test(r#"def florb [ --dry-run ] { $dry_run }; florb"#, "false") +} + +#[test] +fn custom_switch6() -> TestResult { + run_test( + r#"def florb [ --dry-run ] { $dry_run }; florb --dry-run"#, + "true", + ) +} + +#[test] +fn custom_flag1() -> TestResult { run_test( r#"def florb [ --age: int = 0 @@ -96,7 +125,7 @@ fn custom_switch3() -> TestResult { } #[test] -fn custom_switch4() -> TestResult { +fn custom_flag2() -> TestResult { run_test( r#"def florb [ --age: int