forked from extern/nushell
Flags and args on def (#8953)
# Description Fixes #8916 Fix flags and args on def which were call wrong . Added some tests too .
This commit is contained in:
parent
4b8a259916
commit
48c75831fc
@ -112,7 +112,22 @@ pub fn eval_call(
|
||||
if let Some(var_id) = named.var_id {
|
||||
let mut found = false;
|
||||
for call_named in call.named_iter() {
|
||||
if call_named.0.item == named.long {
|
||||
if let (Some(spanned), Some(short)) = (&call_named.1, named.short) {
|
||||
if spanned.item == short.to_string() {
|
||||
if let Some(arg) = &call_named.2 {
|
||||
let result = eval_expression(engine_state, caller_stack, arg)?;
|
||||
|
||||
callee_stack.add_var(var_id, result);
|
||||
} else if let Some(arg) = &named.default_value {
|
||||
let result = eval_expression(engine_state, caller_stack, arg)?;
|
||||
|
||||
callee_stack.add_var(var_id, result);
|
||||
} else {
|
||||
callee_stack.add_var(var_id, Value::boolean(true, call.head))
|
||||
}
|
||||
found = true;
|
||||
}
|
||||
} else if call_named.0.item == named.long {
|
||||
if let Some(arg) = &call_named.2 {
|
||||
let result = eval_expression(engine_state, caller_stack, arg)?;
|
||||
|
||||
|
@ -379,3 +379,27 @@ fn assignment_to_in_var_no_panic() -> TestResult {
|
||||
fn assignment_to_env_no_panic() -> TestResult {
|
||||
fail_test(r#"$env = 3"#, "cannot_replace_env")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn short_flags() -> TestResult {
|
||||
run_test(
|
||||
r#"def foobar [-a: int, -b: string, -c: string] { echo $'($a) ($c) ($b)' }; foobar -b "balh balh" -a 1543 -c "FALSE123""#,
|
||||
"1543 FALSE123 balh balh",
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn short_flags_1() -> TestResult {
|
||||
run_test(
|
||||
r#"def foobar [-a: string, -b: string, -s: int] { if ( $s == 0 ) { echo $'($b)($a)' }}; foobar -a test -b case -s 0 "#,
|
||||
"casetest",
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn short_flags_2() -> TestResult {
|
||||
run_test(
|
||||
r#"def foobar [-a: int, -b: string, -c: int] { $a + $c };foobar -b "balh balh" -a 10 -c 1 "#,
|
||||
"11",
|
||||
)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user