cliparser: pass all arguments to expand_aliases

Summary:
This gives `expand_aliases` a chance to handle things like `$1`, `$2`, etc.

Related Python code assuming `expand_aliases` does not change args was removed.

Reviewed By: kulshrax

Differential Revision: D16530712

fbshipit-source-id: b81c2d29b9b9b5b93ce01627268a999a2cfd1ef0
This commit is contained in:
Jun Wu 2019-07-29 19:30:30 -07:00 committed by Facebook Github Bot
parent 5a36368ef8
commit a9574245ca
2 changed files with 9 additions and 5 deletions

View File

@ -1049,7 +1049,7 @@ def _parse(ui, args):
if args:
try:
replacement, aliases = cliparser.expandargs(
ui._rcfg, commandnames, [args[0]], strict
ui._rcfg, commandnames, args, strict
)
except cliparser.AmbiguousCommand as e:
e.args[2].sort()
@ -1073,8 +1073,13 @@ def _parse(ui, args):
replace = idx
break
fullargs = fullargs[:replace] + replacement + fullargs[replace + 1 :]
replacement = replacement + args[1:]
# FIXME: Find a way to avoid calling expandargs twice.
fullargs = (
fullargs[:replace]
+ cliparser.expandargs(ui._rcfg, commandnames, fullargs[replace:], strict)[
0
]
)
# Only need to figure out the command name. Parse result is dropped.
cmd, _args, a, entry, level = cmdutil.findsubcmd(

View File

@ -400,14 +400,13 @@ impl Dispatcher {
}
}
let (expanded, _replaced) = expand_aliases(alias_lookup, &vec![first_arg.to_string()])
let (expanded, _replaced) = expand_aliases(alias_lookup, &args[replace..])
.map_err(|_| DispatchError::AliasExpansionFailed)?;
let mut new_args = Vec::new();
new_args.extend_from_slice(&args[..replace]);
new_args.extend_from_slice(&expanded[..]);
new_args.extend_from_slice(&args[replace + 1..]);
let command_name = self
.find_command_name(expanded)