From a9574245ca794cf859f837cd74ba4a68532057c2 Mon Sep 17 00:00:00 2001 From: Jun Wu Date: Mon, 29 Jul 2019 19:30:30 -0700 Subject: [PATCH] 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 --- edenscm/mercurial/dispatch.py | 11 ++++++++--- lib/clidispatch/src/dispatch.rs | 3 +-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/edenscm/mercurial/dispatch.py b/edenscm/mercurial/dispatch.py index c0bc823fb1..d3952079d8 100644 --- a/edenscm/mercurial/dispatch.py +++ b/edenscm/mercurial/dispatch.py @@ -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( diff --git a/lib/clidispatch/src/dispatch.rs b/lib/clidispatch/src/dispatch.rs index d2dba53d36..a890eb5ef8 100644 --- a/lib/clidispatch/src/dispatch.rs +++ b/lib/clidispatch/src/dispatch.rs @@ -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)