fix handling short-only args. limitation: long args and short args now share the same namespace, effectively

This commit is contained in:
Devyn Cairns 2024-07-09 03:37:49 -07:00
parent 386a7de467
commit 323e2dbed9
2 changed files with 15 additions and 3 deletions

View File

@ -124,8 +124,12 @@ pub(crate) fn compile_call(
ast_ref,
))
}
Argument::Named((name, _, _)) => compiled_args.push(CompiledArg::Named(
name.item.as_str(),
Argument::Named((name, short, _)) => compiled_args.push(CompiledArg::Named(
if name.item.is_empty() {
&short.as_ref().expect("no long name and no short name").item
} else {
&name.item
},
arg_reg,
arg.span(),
ast_ref,

View File

@ -968,7 +968,15 @@ fn eval_call<D: DebugContext>(
fn find_named_var_id(sig: &Signature, name: &[u8], span: Span) -> Result<VarId, ShellError> {
sig.named
.iter()
.find(|n| n.long.as_bytes() == name)
.find(|n| {
if !n.long.is_empty() {
n.long.as_bytes() == name
} else {
// If the arg has no long name, then compare against its short name
n.short
.is_some_and(|s| s.encode_utf8(&mut [0; 4]).as_bytes() == name)
}
})
.ok_or_else(|| ShellError::IrEvalError {
msg: format!(
"block does not have an argument named `{}`",