Skip to content
Snippets Groups Projects
Commit e4ab5ae193f2 authored by Alexander Solovyov's avatar Alexander Solovyov
Browse files

add positional arguments to non-shell aliases

parent 8e00906066c9
No related branches found
No related tags found
No related merge requests found
......@@ -182,10 +182,21 @@
return -1
def aliasargs(fn):
if hasattr(fn, 'args'):
return fn.args
return []
def aliasargs(fn, givenargs):
args = getattr(fn, 'args', [])
if args and givenargs:
cmd = ' '.join(map(util.shellquote, args))
nums = []
def replacer(m):
num = int(m.group(1)) - 1
nums.append(num)
return givenargs[num]
cmd = re.sub(r'\$(\d+|\$)', replacer, cmd)
givenargs = [x for i, x in enumerate(givenargs)
if i not in nums]
args = shlex.split(cmd)
return args + givenargs
class cmdalias(object):
def __init__(self, name, definition, cmdtable):
......@@ -263,7 +274,7 @@
else:
self.fn, self.opts = tableentry
self.args = aliasargs(self.fn) + args
self.args = aliasargs(self.fn, args)
if cmd not in commands.norepo.split(' '):
self.norepo = False
if self.help.startswith("hg " + cmd):
......@@ -330,7 +341,7 @@
aliases, entry = cmdutil.findcmd(cmd, commands.table,
ui.config("ui", "strict"))
cmd = aliases[0]
args = aliasargs(entry[0]) + args
args = aliasargs(entry[0], args)
defaults = ui.config("defaults", cmd)
if defaults:
args = map(util.expandpath, shlex.split(defaults)) + args
......
......@@ -17,6 +17,7 @@
> mylog = log
> lognull = log -r null
> shortlog = log --template '{rev} {node|short} | {date|isodate}\n'
> positional = log --template '{\$2} {\$1} | {date|isodate}\n'
> dln = lognull --debug
> nousage = rollback
> put = export -r 0 -o "\$FOO/%R.diff"
......@@ -127,6 +128,10 @@
$ hg shortlog
0 e63c23eaa88a | 1970-01-01 00:00 +0000
positional arguments
$ hg positional 'node|short' rev
0 e63c23eaa88a | 1970-01-01 00:00 +0000
interaction with defaults
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment