comparison mercurial/commands.py @ 15022:bf1fa4ba582b

help: move 'additional help topics' code
author Matt Mackall <mpm@selenic.com>
date Thu, 04 Aug 2011 15:36:15 -0500
parents 607f1434501d
children 157a294444b2
comparison
equal deleted inserted replaced
15021:573e82fef44d 15022:bf1fa4ba582b
2587 Given a topic, extension, or command name, print help for that 2587 Given a topic, extension, or command name, print help for that
2588 topic. 2588 topic.
2589 2589
2590 Returns 0 if successful. 2590 Returns 0 if successful.
2591 """ 2591 """
2592 option_lists = [] 2592 optlist = []
2593 textwidth = min(ui.termwidth(), 80) - 2 2593 textwidth = min(ui.termwidth(), 80) - 2
2594 2594
2595 def addglobalopts(aliases): 2595 def addglobalopts(aliases):
2596 if ui.verbose: 2596 if ui.verbose:
2597 option_lists.append((_("global options:"), globalopts)) 2597 optlist.append((_("global options:"), globalopts))
2598 if name == 'shortlist': 2598 if name == 'shortlist':
2599 option_lists.append((_('use "hg help" for the full list ' 2599 optlist.append((_('use "hg help" for the full list '
2600 'of commands'), ())) 2600 'of commands'), ()))
2601 else: 2601 else:
2602 if name == 'shortlist': 2602 if name == 'shortlist':
2603 msg = _('use "hg help" for the full list of commands ' 2603 msg = _('use "hg help" for the full list of commands '
2604 'or "hg -v" for details') 2604 'or "hg -v" for details')
2607 elif aliases: 2607 elif aliases:
2608 msg = _('use "hg -v help%s" to show builtin aliases and ' 2608 msg = _('use "hg -v help%s" to show builtin aliases and '
2609 'global options') % (name and " " + name or "") 2609 'global options') % (name and " " + name or "")
2610 else: 2610 else:
2611 msg = _('use "hg -v help %s" to show global options') % name 2611 msg = _('use "hg -v help %s" to show global options') % name
2612 option_lists.append((msg, ())) 2612 optlist.append((msg, ()))
2613 2613
2614 def helpcmd(name): 2614 def helpcmd(name):
2615 try: 2615 try:
2616 aliases, entry = cmdutil.findcmd(name, table, strict=unknowncmd) 2616 aliases, entry = cmdutil.findcmd(name, table, strict=unknowncmd)
2617 except error.AmbiguousCommand, inst: 2617 except error.AmbiguousCommand, inst:
2659 ui.write(_('\nuse "hg -v help %s" to show verbose help\n') % name) 2659 ui.write(_('\nuse "hg -v help %s" to show verbose help\n') % name)
2660 2660
2661 if not ui.quiet: 2661 if not ui.quiet:
2662 # options 2662 # options
2663 if entry[1]: 2663 if entry[1]:
2664 option_lists.append((_("options:\n"), entry[1])) 2664 optlist.append((_("options:\n"), entry[1]))
2665 2665
2666 addglobalopts(False) 2666 addglobalopts(False)
2667 2667
2668 # check if this command shadows a non-trivial (multi-line) 2668 # check if this command shadows a non-trivial (multi-line)
2669 # extension help text 2669 # extension help text
2818 if name != 'shortlist': 2818 if name != 'shortlist':
2819 text = help.listexts(_('enabled extensions:'), extensions.enabled()) 2819 text = help.listexts(_('enabled extensions:'), extensions.enabled())
2820 if text: 2820 if text:
2821 ui.write("\n%s\n" % minirst.format(text, textwidth)) 2821 ui.write("\n%s\n" % minirst.format(text, textwidth))
2822 2822
2823 if not name:
2824 ui.write(_("\nadditional help topics:\n\n"))
2825 topics = []
2826 for names, header, doc in help.helptable:
2827 topics.append((sorted(names, key=len, reverse=True)[0], header))
2828 topics_len = max([len(s[0]) for s in topics])
2829 for t, desc in topics:
2830 ui.write(" %-*s %s\n" % (topics_len, t, desc))
2831
2823 # list all option lists 2832 # list all option lists
2824 opt_output = [] 2833 opt_output = []
2825 multioccur = False 2834 multioccur = False
2826 for title, options in option_lists: 2835 for title, options in optlist:
2827 opt_output.append(("\n%s" % title, None)) 2836 opt_output.append(("\n%s" % title, None))
2828 for option in options: 2837 for option in options:
2829 if len(option) == 5: 2838 if len(option) == 5:
2830 shortopt, longopt, default, desc, optlabel = option 2839 shortopt, longopt, default, desc, optlabel = option
2831 else: 2840 else:
2853 msg = _("\n[+] marked option can be specified multiple times") 2862 msg = _("\n[+] marked option can be specified multiple times")
2854 if ui.verbose and name != 'shortlist': 2863 if ui.verbose and name != 'shortlist':
2855 opt_output.append((msg, None)) 2864 opt_output.append((msg, None))
2856 else: 2865 else:
2857 opt_output.insert(-1, (msg, None)) 2866 opt_output.insert(-1, (msg, None))
2858
2859 if not name:
2860 ui.write(_("\nadditional help topics:\n\n"))
2861 topics = []
2862 for names, header, doc in help.helptable:
2863 topics.append((sorted(names, key=len, reverse=True)[0], header))
2864 topics_len = max([len(s[0]) for s in topics])
2865 for t, desc in topics:
2866 ui.write(" %-*s %s\n" % (topics_len, t, desc))
2867 2867
2868 if opt_output: 2868 if opt_output:
2869 colwidth = encoding.colwidth 2869 colwidth = encoding.colwidth
2870 # normalize: (opt or message, desc or None, width of opt) 2870 # normalize: (opt or message, desc or None, width of opt)
2871 entries = [desc and (opt, desc, colwidth(opt)) or (opt, None, 0) 2871 entries = [desc and (opt, desc, colwidth(opt)) or (opt, None, 0)