##// END OF EJS Templates
help: make "hg help EXTENSION" work
Vadim Gelfer -
r2553:5b426676 default
parent child Browse files
Show More
@@ -534,14 +534,22 b' def show_version(ui):'
534 534 "not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"
535 535 ))
536 536
537 def help_(ui, cmd=None, with_version=False):
538 """show help for a given command or all commands"""
537 def help_(ui, name=None, with_version=False):
538 """show help for a command, extension, or list of commands
539
540 With no arguments, print a list of commands and short help.
541
542 Given a command name, print help for that command.
543
544 Given an extension name, print help for that extension, and the
545 commands it provides."""
539 546 option_lists = []
540 if cmd and cmd != 'shortlist':
547
548 def helpcmd(name):
541 549 if with_version:
542 550 show_version(ui)
543 551 ui.write('\n')
544 aliases, i = find(cmd)
552 aliases, i = findcmd(name)
545 553 # synopsis
546 554 ui.write("%s\n\n" % i[2])
547 555
@@ -561,30 +569,15 b' def help_(ui, cmd=None, with_version=Fal'
561 569 # options
562 570 if i[1]:
563 571 option_lists.append(("options", i[1]))
564
565 else:
566 # program name
567 if ui.verbose or with_version:
568 show_version(ui)
569 else:
570 ui.status(_("Mercurial Distributed SCM\n"))
571 ui.status('\n')
572
573 # list of commands
574 if cmd == "shortlist":
575 ui.status(_('basic commands (use "hg help" '
576 'for the full list or option "-v" for details):\n\n'))
577 elif ui.verbose:
578 ui.status(_('list of commands:\n\n'))
579 else:
580 ui.status(_('list of commands (use "hg help -v" '
581 'to show aliases and global options):\n\n'))
582
572
573 def helplist(select=None):
583 574 h = {}
584 575 cmds = {}
585 576 for c, e in table.items():
586 f = c.split("|")[0]
587 if cmd == "shortlist" and not f.startswith("^"):
577 f = c.split("|", 1)[0]
578 if select and not select(f):
579 continue
580 if name == "shortlist" and not f.startswith("^"):
588 581 continue
589 582 f = f.lstrip("^")
590 583 if not ui.debugflag and f.startswith("debug"):
@@ -605,6 +598,53 b' def help_(ui, cmd=None, with_version=Fal'
605 598 else:
606 599 ui.write(' %-*s %s\n' % (m, f, h[f]))
607 600
601 def helpext(name):
602 try:
603 mod = findext(name)
604 except KeyError:
605 raise UnknownCommand(name)
606
607 doc = (mod.__doc__ or _('No help text available')).splitlines(0)
608 ui.write(_('%s extension - %s\n') % (name.split('.')[-1], doc[0]))
609 for d in doc[1:]:
610 ui.write(d, '\n')
611
612 ui.status('\n')
613 if ui.verbose:
614 ui.status(_('list of commands:\n\n'))
615 else:
616 ui.status(_('list of commands (use "hg help -v %s" '
617 'to show aliases and global options):\n\n') % name)
618
619 modcmds = dict.fromkeys([c.split('|', 1)[0] for c in mod.cmdtable])
620 helplist(modcmds.has_key)
621
622 if name and name != 'shortlist':
623 try:
624 helpcmd(name)
625 except UnknownCommand:
626 helpext(name)
627
628 else:
629 # program name
630 if ui.verbose or with_version:
631 show_version(ui)
632 else:
633 ui.status(_("Mercurial Distributed SCM\n"))
634 ui.status('\n')
635
636 # list of commands
637 if name == "shortlist":
638 ui.status(_('basic commands (use "hg help" '
639 'for the full list or option "-v" for details):\n\n'))
640 elif ui.verbose:
641 ui.status(_('list of commands:\n\n'))
642 else:
643 ui.status(_('list of commands (use "hg help -v" '
644 'to show aliases and global options):\n\n'))
645
646 helplist()
647
608 648 # global options
609 649 if ui.verbose:
610 650 option_lists.append(("global options", globalopts))
@@ -1254,7 +1294,7 b" def debugcomplete(ui, cmd='', **opts):"
1254 1294 options = []
1255 1295 otables = [globalopts]
1256 1296 if cmd:
1257 aliases, entry = find(cmd)
1297 aliases, entry = findcmd(cmd)
1258 1298 otables.append(entry[1])
1259 1299 for t in otables:
1260 1300 for o in t:
@@ -3274,7 +3314,7 b' def findpossible(cmd):'
3274 3314
3275 3315 return choice
3276 3316
3277 def find(cmd):
3317 def findcmd(cmd):
3278 3318 """Return (aliases, command table entry) for command string."""
3279 3319 choice = findpossible(cmd)
3280 3320
@@ -3311,7 +3351,7 b' def parse(ui, args):'
3311 3351
3312 3352 if args:
3313 3353 cmd, args = args[0], args[1:]
3314 aliases, i = find(cmd)
3354 aliases, i = findcmd(cmd)
3315 3355 cmd = aliases[0]
3316 3356 defaults = ui.config("defaults", cmd)
3317 3357 if defaults:
@@ -3338,6 +3378,19 b' def parse(ui, args):'
3338 3378
3339 3379 return (cmd, cmd and i[0] or None, args, options, cmdoptions)
3340 3380
3381 external = {}
3382
3383 def findext(name):
3384 '''return module with given extension name'''
3385 try:
3386 return external[name]
3387 except KeyError:
3388 dotname = '.' + name
3389 for k, v in external.iteritems():
3390 if k.endswith('.' + name) or v.__name__ == name:
3391 return v
3392 raise KeyError(name)
3393
3341 3394 def dispatch(args):
3342 3395 for name in 'SIGBREAK', 'SIGHUP', 'SIGTERM':
3343 3396 num = getattr(signal, name, None)
@@ -3349,7 +3402,6 b' def dispatch(args):'
3349 3402 sys.stderr.write(_("abort: %s\n") % inst)
3350 3403 return -1
3351 3404
3352 external = []
3353 3405 for x in u.extensions():
3354 3406 try:
3355 3407 if x[1]:
@@ -3366,10 +3418,12 b' def dispatch(args):'
3366 3418 mod = getattr(mod, comp)
3367 3419 return mod
3368 3420 try:
3369 mod = importh("hgext." + x[0])
3421 name = 'hgext.' + x[0]
3422 mod = importh(name)
3370 3423 except ImportError:
3371 mod = importh(x[0])
3372 external.append(mod)
3424 name = x[0]
3425 mod = importh(name)
3426 external[name] = mod
3373 3427 except (util.SignalInterrupt, KeyboardInterrupt):
3374 3428 raise
3375 3429 except Exception, inst:
@@ -3377,7 +3431,7 b' def dispatch(args):'
3377 3431 if u.print_exc():
3378 3432 return 1
3379 3433
3380 for x in external:
3434 for x in external.itervalues():
3381 3435 uisetup = getattr(x, 'uisetup', None)
3382 3436 if uisetup:
3383 3437 uisetup(u)
@@ -3433,7 +3487,7 b' def dispatch(args):'
3433 3487 if not repo:
3434 3488 repo = hg.repository(u, path=path)
3435 3489 u = repo.ui
3436 for x in external:
3490 for x in external.itervalues():
3437 3491 if hasattr(x, 'reposetup'):
3438 3492 x.reposetup(u, repo)
3439 3493 except hg.RepoError:
@@ -127,7 +127,7 b' list of commands (use "hg help -v" to sh'
127 127 export dump the header and diffs for one or more changesets
128 128 grep search for a pattern in specified files and revisions
129 129 heads show current repository heads
130 help show help for a given command or all commands
130 help show help for a command, extension, or list of commands
131 131 identify print information about the working copy
132 132 import import an ordered set of patches
133 133 incoming show new changesets found in source
@@ -173,7 +173,7 b' list of commands (use "hg help -v" to sh'
173 173 export dump the header and diffs for one or more changesets
174 174 grep search for a pattern in specified files and revisions
175 175 heads show current repository heads
176 help show help for a given command or all commands
176 help show help for a command, extension, or list of commands
177 177 identify print information about the working copy
178 178 import import an ordered set of patches
179 179 incoming show new changesets found in source
@@ -51,7 +51,7 b' list of commands (use "hg help -v" to sh'
51 51 export dump the header and diffs for one or more changesets
52 52 grep search for a pattern in specified files and revisions
53 53 heads show current repository heads
54 help show help for a given command or all commands
54 help show help for a command, extension, or list of commands
55 55 identify print information about the working copy
56 56 import import an ordered set of patches
57 57 incoming show new changesets found in source
@@ -93,7 +93,7 b' list of commands (use "hg help -v" to sh'
93 93 export dump the header and diffs for one or more changesets
94 94 grep search for a pattern in specified files and revisions
95 95 heads show current repository heads
96 help show help for a given command or all commands
96 help show help for a command, extension, or list of commands
97 97 identify print information about the working copy
98 98 import import an ordered set of patches
99 99 incoming show new changesets found in source
General Comments 0
You need to be logged in to leave comments. Login now