##// END OF EJS Templates
help: supporting both help and doc for aliases...
Rodrigo Damazio -
r37152:6890b7e9 default
parent child Browse files
Show More
@@ -427,7 +427,7 b' def extsetup(ui):'
427 continue
427 continue
428
428
429 # Same for aliases.
429 # Same for aliases.
430 if ui.config('alias', name):
430 if ui.config('alias', name, None):
431 continue
431 continue
432
432
433 ui.setconfig('alias', name, 'show %s' % view, source='show')
433 ui.setconfig('alias', name, 'show %s' % view, source='show')
@@ -114,7 +114,7 b' def getitemregister(configtable):'
114 coreconfigitem = getitemregister(coreitems)
114 coreconfigitem = getitemregister(coreitems)
115
115
116 coreconfigitem('alias', '.*',
116 coreconfigitem('alias', '.*',
117 default=None,
117 default=dynamicdefault,
118 generic=True,
118 generic=True,
119 )
119 )
120 coreconfigitem('annotate', 'nodates',
120 coreconfigitem('annotate', 'nodates',
@@ -450,7 +450,7 b' def aliasinterpolate(name, args, cmd):'
450 return r.sub(lambda x: replacemap[x.group()], cmd)
450 return r.sub(lambda x: replacemap[x.group()], cmd)
451
451
452 class cmdalias(object):
452 class cmdalias(object):
453 def __init__(self, name, definition, cmdtable, source):
453 def __init__(self, ui, name, definition, cmdtable, source):
454 self.name = self.cmd = name
454 self.name = self.cmd = name
455 self.cmdname = ''
455 self.cmdname = ''
456 self.definition = definition
456 self.definition = definition
@@ -477,6 +477,7 b' class cmdalias(object):'
477 return
477 return
478
478
479 if self.definition.startswith('!'):
479 if self.definition.startswith('!'):
480 shdef = self.definition[1:]
480 self.shell = True
481 self.shell = True
481 def fn(ui, *args):
482 def fn(ui, *args):
482 env = {'HG_ARGS': ' '.join((self.name,) + args)}
483 env = {'HG_ARGS': ' '.join((self.name,) + args)}
@@ -490,11 +491,12 b' class cmdalias(object):'
490 "of %i variable in alias '%s' definition.\n"
491 "of %i variable in alias '%s' definition.\n"
491 % (int(m.groups()[0]), self.name))
492 % (int(m.groups()[0]), self.name))
492 return ''
493 return ''
493 cmd = re.sub(br'\$(\d+|\$)', _checkvar, self.definition[1:])
494 cmd = re.sub(br'\$(\d+|\$)', _checkvar, shdef)
494 cmd = aliasinterpolate(self.name, args, cmd)
495 cmd = aliasinterpolate(self.name, args, cmd)
495 return ui.system(cmd, environ=env,
496 return ui.system(cmd, environ=env,
496 blockedtag='alias_%s' % self.name)
497 blockedtag='alias_%s' % self.name)
497 self.fn = fn
498 self.fn = fn
499 self._populatehelp(ui, name, shdef, self.fn)
498 return
500 return
499
501
500 try:
502 try:
@@ -516,14 +518,12 b' class cmdalias(object):'
516 try:
518 try:
517 tableentry = cmdutil.findcmd(cmd, cmdtable, False)[1]
519 tableentry = cmdutil.findcmd(cmd, cmdtable, False)[1]
518 if len(tableentry) > 2:
520 if len(tableentry) > 2:
519 self.fn, self.opts, self.help = tableentry
521 self.fn, self.opts, cmdhelp = tableentry
520 else:
522 else:
521 self.fn, self.opts = tableentry
523 self.fn, self.opts = tableentry
524 cmdhelp = None
522
525
523 if self.help.startswith("hg " + cmd):
526 self._populatehelp(ui, name, cmd, self.fn, cmdhelp)
524 # drop prefix in old-style help lines so hg shows the alias
525 self.help = self.help[4 + len(cmd):]
526 self.__doc__ = self.fn.__doc__
527
527
528 except error.UnknownCommand:
528 except error.UnknownCommand:
529 self.badalias = (_("alias '%s' resolves to unknown command '%s'")
529 self.badalias = (_("alias '%s' resolves to unknown command '%s'")
@@ -533,6 +533,14 b' class cmdalias(object):'
533 self.badalias = (_("alias '%s' resolves to ambiguous command '%s'")
533 self.badalias = (_("alias '%s' resolves to ambiguous command '%s'")
534 % (self.name, cmd))
534 % (self.name, cmd))
535
535
536 def _populatehelp(self, ui, name, cmd, fn, defaulthelp=None):
537 self.help = ui.config('alias', '%s:help' % name, defaulthelp or '')
538 if self.help and self.help.startswith("hg " + cmd):
539 # drop prefix in old-style help lines so hg shows the alias
540 self.help = self.help[4 + len(cmd):]
541
542 self.__doc__ = ui.config('alias', '%s:doc' % name, fn.__doc__)
543
536 @property
544 @property
537 def args(self):
545 def args(self):
538 args = pycompat.maplist(util.expandpath, self.givenargs)
546 args = pycompat.maplist(util.expandpath, self.givenargs)
@@ -577,7 +585,8 b' class cmdalias(object):'
577 class lazyaliasentry(object):
585 class lazyaliasentry(object):
578 """like a typical command entry (func, opts, help), but is lazy"""
586 """like a typical command entry (func, opts, help), but is lazy"""
579
587
580 def __init__(self, name, definition, cmdtable, source):
588 def __init__(self, ui, name, definition, cmdtable, source):
589 self.ui = ui
581 self.name = name
590 self.name = name
582 self.definition = definition
591 self.definition = definition
583 self.cmdtable = cmdtable.copy()
592 self.cmdtable = cmdtable.copy()
@@ -585,7 +594,8 b' class lazyaliasentry(object):'
585
594
586 @util.propertycache
595 @util.propertycache
587 def _aliasdef(self):
596 def _aliasdef(self):
588 return cmdalias(self.name, self.definition, self.cmdtable, self.source)
597 return cmdalias(self.ui, self.name, self.definition, self.cmdtable,
598 self.source)
589
599
590 def __getitem__(self, n):
600 def __getitem__(self, n):
591 aliasdef = self._aliasdef
601 aliasdef = self._aliasdef
@@ -609,7 +619,7 b' def addaliases(ui, cmdtable):'
609 # aliases are processed after extensions have been loaded, so they
619 # aliases are processed after extensions have been loaded, so they
610 # may use extension commands. Aliases can also use other alias definitions,
620 # may use extension commands. Aliases can also use other alias definitions,
611 # but only if they have been defined prior to the current definition.
621 # but only if they have been defined prior to the current definition.
612 for alias, definition in ui.configitems('alias'):
622 for alias, definition in ui.configitems('alias', ignoresub=True):
613 try:
623 try:
614 if cmdtable[alias].definition == definition:
624 if cmdtable[alias].definition == definition:
615 continue
625 continue
@@ -618,7 +628,7 b' def addaliases(ui, cmdtable):'
618 pass
628 pass
619
629
620 source = ui.configsource('alias', alias)
630 source = ui.configsource('alias', alias)
621 entry = lazyaliasentry(alias, definition, cmdtable, source)
631 entry = lazyaliasentry(ui, alias, definition, cmdtable, source)
622 cmdtable[alias] = entry
632 cmdtable[alias] = entry
623
633
624 def _parse(ui, args):
634 def _parse(ui, args):
@@ -370,8 +370,8 b' def help_(ui, commands, name, unknowncmd'
370 if util.safehasattr(entry[0], 'definition'): # aliased command
370 if util.safehasattr(entry[0], 'definition'): # aliased command
371 source = entry[0].source
371 source = entry[0].source
372 if entry[0].definition.startswith('!'): # shell alias
372 if entry[0].definition.startswith('!'): # shell alias
373 doc = (_('shell alias for::\n\n %s\n\ndefined by: %s\n') %
373 doc = (_('shell alias for: %s\n\n%s\n\ndefined by: %s\n') %
374 (entry[0].definition[1:], source))
374 (entry[0].definition[1:], doc, source))
375 else:
375 else:
376 doc = (_('alias for: hg %s\n\n%s\n\ndefined by: %s\n') %
376 doc = (_('alias for: hg %s\n\n%s\n\ndefined by: %s\n') %
377 (entry[0].definition, doc, source))
377 (entry[0].definition, doc, source))
@@ -739,11 +739,7 b' class ui(object):'
739 def configitems(self, section, untrusted=False, ignoresub=False):
739 def configitems(self, section, untrusted=False, ignoresub=False):
740 items = self._data(untrusted).items(section)
740 items = self._data(untrusted).items(section)
741 if ignoresub:
741 if ignoresub:
742 newitems = {}
742 items = [i for i in items if ':' not in i[0]]
743 for k, v in items:
744 if ':' not in k:
745 newitems[k] = v
746 items = list(newitems.iteritems())
747 if self.debugflag and not untrusted and self._reportuntrusted:
743 if self.debugflag and not untrusted and self._reportuntrusted:
748 for k, v in self._ucfg.items(section):
744 for k, v in self._ucfg.items(section):
749 if self._tcfg.get(section, k) != v:
745 if self._tcfg.get(section, k) != v:
@@ -4,9 +4,13 b''
4 > # should clobber ci but not commit (issue2993)
4 > # should clobber ci but not commit (issue2993)
5 > ci = version
5 > ci = version
6 > myinit = init
6 > myinit = init
7 > myinit:doc = This is my documented alias for init.
8 > myinit:help = [OPTIONS] [BLA] [BLE]
7 > mycommit = commit
9 > mycommit = commit
10 > mycommit:doc = This is my alias with only doc.
8 > optionalrepo = showconfig alias.myinit
11 > optionalrepo = showconfig alias.myinit
9 > cleanstatus = status -c
12 > cleanstatus = status -c
13 > cleanstatus:help = [ONLYHELPHERE]
10 > unknown = bargle
14 > unknown = bargle
11 > ambiguous = s
15 > ambiguous = s
12 > recursive = recursive
16 > recursive = recursive
@@ -20,9 +24,13 b''
20 > no--config = status --config a.config=1
24 > no--config = status --config a.config=1
21 > mylog = log
25 > mylog = log
22 > lognull = log -r null
26 > lognull = log -r null
27 > lognull:doc = Logs the null rev
28 > lognull:help = foo bar baz
23 > shortlog = log --template '{rev} {node|short} | {date|isodate}\n'
29 > shortlog = log --template '{rev} {node|short} | {date|isodate}\n'
24 > positional = log --template '{\$2} {\$1} | {date|isodate}\n'
30 > positional = log --template '{\$2} {\$1} | {date|isodate}\n'
25 > dln = lognull --debug
31 > dln = lognull --debug
32 > recursivedoc = dln
33 > recursivedoc:doc = Logs the null rev in debug mode
26 > nousage = rollback
34 > nousage = rollback
27 > put = export -r 0 -o "\$FOO/%R.diff"
35 > put = export -r 0 -o "\$FOO/%R.diff"
28 > blank = !printf '\n'
36 > blank = !printf '\n'
@@ -53,11 +61,148 b''
53 > log = -v
61 > log = -v
54 > EOF
62 > EOF
55
63
56
57 basic
64 basic
58
65
59 $ hg myinit alias
66 $ hg myinit alias
60
67
68 help
69
70 $ hg help -c | grep myinit
71 myinit This is my documented alias for init.
72 $ hg help -c | grep mycommit
73 mycommit This is my alias with only doc.
74 $ hg help -c | grep cleanstatus
75 cleanstatus show changed files in the working directory
76 $ hg help -c | grep lognull
77 lognull Logs the null rev
78 $ hg help -c | grep dln
79 dln Logs the null rev
80 $ hg help -c | grep recursivedoc
81 recursivedoc Logs the null rev in debug mode
82 $ hg help myinit
83 hg myinit [OPTIONS] [BLA] [BLE]
84
85 alias for: hg init
86
87 This is my documented alias for init.
88
89 defined by: * (glob)
90 */* (glob) (?)
91 */* (glob) (?)
92 */* (glob) (?)
93
94 options:
95
96 -e --ssh CMD specify ssh command to use
97 --remotecmd CMD specify hg command to run on the remote side
98 --insecure do not verify server certificate (ignoring web.cacerts
99 config)
100
101 (some details hidden, use --verbose to show complete help)
102
103 $ hg help mycommit
104 hg mycommit [OPTION]... [FILE]...
105
106 alias for: hg commit
107
108 This is my alias with only doc.
109
110 defined by: * (glob)
111 */* (glob) (?)
112 */* (glob) (?)
113 */* (glob) (?)
114
115 options ([+] can be repeated):
116
117 -A --addremove mark new/missing files as added/removed before
118 committing
119 --close-branch mark a branch head as closed
120 --amend amend the parent of the working directory
121 -s --secret use the secret phase for committing
122 -e --edit invoke editor on commit messages
123 -i --interactive use interactive mode
124 -I --include PATTERN [+] include names matching the given patterns
125 -X --exclude PATTERN [+] exclude names matching the given patterns
126 -m --message TEXT use text as commit message
127 -l --logfile FILE read commit message from file
128 -d --date DATE record the specified date as commit date
129 -u --user USER record the specified user as committer
130 -S --subrepos recurse into subrepositories
131
132 (some details hidden, use --verbose to show complete help)
133
134 $ hg help cleanstatus
135 hg cleanstatus [ONLYHELPHERE]
136
137 alias for: hg status -c
138
139 show changed files in the working directory
140
141 Show status of files in the repository. If names are given, only files
142 that match are shown. Files that are clean or ignored or the source of a
143 copy/move operation, are not listed unless -c/--clean, -i/--ignored,
144 -C/--copies or -A/--all are given. Unless options described with "show
145 only ..." are given, the options -mardu are used.
146
147 Option -q/--quiet hides untracked (unknown and ignored) files unless
148 explicitly requested with -u/--unknown or -i/--ignored.
149
150 Note:
151 'hg status' may appear to disagree with diff if permissions have
152 changed or a merge has occurred. The standard diff format does not
153 report permission changes and diff only reports changes relative to one
154 merge parent.
155
156 If one revision is given, it is used as the base revision. If two
157 revisions are given, the differences between them are shown. The --change
158 option can also be used as a shortcut to list the changed files of a
159 revision from its first parent.
160
161 The codes used to show the status of files are:
162
163 M = modified
164 A = added
165 R = removed
166 C = clean
167 ! = missing (deleted by non-hg command, but still tracked)
168 ? = not tracked
169 I = ignored
170 = origin of the previous file (with --copies)
171
172 Returns 0 on success.
173
174 defined by: * (glob)
175 */* (glob) (?)
176 */* (glob) (?)
177 */* (glob) (?)
178
179 options ([+] can be repeated):
180
181 -A --all show status of all files
182 -m --modified show only modified files
183 -a --added show only added files
184 -r --removed show only removed files
185 -d --deleted show only deleted (but tracked) files
186 -c --clean show only files without changes
187 -u --unknown show only unknown (not tracked) files
188 -i --ignored show only ignored files
189 -n --no-status hide status prefix
190 -C --copies show source of copied files
191 -0 --print0 end filenames with NUL, for use with xargs
192 --rev REV [+] show difference from revision
193 --change REV list the changed files of a revision
194 -I --include PATTERN [+] include names matching the given patterns
195 -X --exclude PATTERN [+] exclude names matching the given patterns
196 -S --subrepos recurse into subrepositories
197
198 (some details hidden, use --verbose to show complete help)
199
200 $ hg help recursivedoc | head -n 5
201 hg recursivedoc foo bar baz
202
203 alias for: hg dln
204
205 Logs the null rev in debug mode
61
206
62 unknown
207 unknown
63
208
@@ -440,6 +585,10 b' command provided extension, should be ab'
440 > rebate = !echo this is \$HG_ARGS
585 > rebate = !echo this is \$HG_ARGS
441 > EOF
586 > EOF
442 #endif
587 #endif
588 $ cat >> .hg/hgrc <<EOF
589 > rebate:doc = This is my alias which just prints something.
590 > rebate:help = [MYARGS]
591 > EOF
443 $ hg reba
592 $ hg reba
444 hg: command 'reba' is ambiguous:
593 hg: command 'reba' is ambiguous:
445 rebase rebate
594 rebase rebate
@@ -449,6 +598,24 b' command provided extension, should be ab'
449 $ hg rebat --foo-bar
598 $ hg rebat --foo-bar
450 this is rebate --foo-bar
599 this is rebate --foo-bar
451
600
601 help for a shell alias
602
603 $ hg help -c | grep rebate
604 rebate This is my alias which just prints something.
605 $ hg help rebate
606 hg rebate [MYARGS]
607
608 shell alias for: echo this is $HG_ARGS
609
610 This is my alias which just prints something.
611
612 defined by:* (glob)
613 */* (glob) (?)
614 */* (glob) (?)
615 */* (glob) (?)
616
617 (some details hidden, use --verbose to show complete help)
618
452 invalid arguments
619 invalid arguments
453
620
454 $ hg rt foo
621 $ hg rt foo
@@ -777,9 +777,9 b' Test for aliases'
777 $ hg help shellalias
777 $ hg help shellalias
778 hg shellalias
778 hg shellalias
779
779
780 shell alias for:
780 shell alias for: echo hi
781
781
782 echo hi
782 (no help text available)
783
783
784 defined by: helpext
784 defined by: helpext
785
785
General Comments 0
You need to be logged in to leave comments. Login now