comparison mercurial/commands.py @ 15145:ff26712a0c50

help: use RST to format option lists
author Matt Mackall <mpm@selenic.com>
date Wed, 21 Sep 2011 13:00:48 -0500
parents 0834e0bb445a
children 395ca8cd2669
comparison
equal deleted inserted replaced
15144:87bb975a1844 15145:ff26712a0c50
2707 Returns 0 if successful. 2707 Returns 0 if successful.
2708 """ 2708 """
2709 2709
2710 textwidth = min(ui.termwidth(), 80) - 2 2710 textwidth = min(ui.termwidth(), 80) - 2
2711 2711
2712 def optrst(options):
2713 data = []
2714 multioccur = False
2715 for option in options:
2716 if len(option) == 5:
2717 shortopt, longopt, default, desc, optlabel = option
2718 else:
2719 shortopt, longopt, default, desc = option
2720 optlabel = _("VALUE") # default label
2721
2722 if _("DEPRECATED") in desc and not ui.verbose:
2723 continue
2724
2725 so = ''
2726 if shortopt:
2727 so = '-' + shortopt
2728 lo = '--' + longopt
2729 if default:
2730 desc += _(" (default: %s)") % default
2731
2732 if isinstance(default, list):
2733 lo += " %s [+]" % optlabel
2734 multioccur = True
2735 elif (default is not None) and not isinstance(default, bool):
2736 lo += " %s" % optlabel
2737
2738 data.append((so, lo, desc))
2739
2740 rst = minirst.maketable(data, 1)
2741 if multioccur:
2742 rst += _("\n[+] marked option can be specified multiple times")
2743
2744 return rst
2745
2712 # list all option lists 2746 # list all option lists
2713 def opttext(optlist, width): 2747 def opttext(optlist, width):
2714 out = [] 2748 rst = ''
2715 multioccur = False 2749 if not optlist:
2750 return ''
2751
2716 for title, options in optlist: 2752 for title, options in optlist:
2717 out.append(("\n%s" % title, None)) 2753 rst += '\n%s\n\n' % title
2718 for option in options: 2754 rst += optrst(options)
2719 if len(option) == 5: 2755 rst += '\n'
2720 shortopt, longopt, default, desc, optlabel = option 2756
2721 else: 2757 return '\n' + minirst.format(rst, width)
2722 shortopt, longopt, default, desc = option
2723 optlabel = _("VALUE") # default label
2724
2725 if _("DEPRECATED") in desc and not ui.verbose:
2726 continue
2727 if isinstance(default, list):
2728 numqualifier = " %s [+]" % optlabel
2729 multioccur = True
2730 elif (default is not None) and not isinstance(default, bool):
2731 numqualifier = " %s" % optlabel
2732 else:
2733 numqualifier = ""
2734 out.append(("%2s%s" %
2735 (shortopt and "-%s" % shortopt,
2736 longopt and " --%s%s" %
2737 (longopt, numqualifier)),
2738 "%s%s" % (desc,
2739 default
2740 and _(" (default: %s)") % default
2741 or "")))
2742 if multioccur:
2743 msg = _("\n[+] marked option can be specified multiple times")
2744 if ui.verbose and name != 'shortlist':
2745 out.append((msg, None))
2746 else:
2747 out.insert(-1, (msg, None))
2748
2749 text = ""
2750 if out:
2751 colwidth = encoding.colwidth
2752 # normalize: (opt or message, desc or None, width of opt)
2753 entries = [desc and (opt, desc, colwidth(opt)) or (opt, None, 0)
2754 for opt, desc in out]
2755 hanging = max([e[2] for e in entries])
2756 for opt, desc, width in entries:
2757 if desc:
2758 initindent = ' %s%s ' % (opt, ' ' * (hanging - width))
2759 hangindent = ' ' * (hanging + 3)
2760 text += '%s\n' % (util.wrap(desc, width,
2761 initindent=initindent,
2762 hangindent=hangindent))
2763 else:
2764 text += "%s\n" % opt
2765
2766 return text
2767 2758
2768 def addglobalopts(optlist, aliases): 2759 def addglobalopts(optlist, aliases):
2769 if ui.quiet: 2760 if ui.quiet:
2770 return [] 2761 return []
2771 2762