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 |
2592 optlist = [] |
2593 optlist = [] |
2593 textwidth = min(ui.termwidth(), 80) - 2 |
2594 textwidth = min(ui.termwidth(), 80) - 2 |
|
2595 |
|
2596 # list all option lists |
|
2597 def opttext(optlist, width): |
|
2598 out = [] |
|
2599 multioccur = False |
|
2600 for title, options in optlist: |
|
2601 out.append(("\n%s" % title, None)) |
|
2602 for option in options: |
|
2603 if len(option) == 5: |
|
2604 shortopt, longopt, default, desc, optlabel = option |
|
2605 else: |
|
2606 shortopt, longopt, default, desc = option |
|
2607 optlabel = _("VALUE") # default label |
|
2608 |
|
2609 if _("DEPRECATED") in desc and not ui.verbose: |
|
2610 continue |
|
2611 if isinstance(default, list): |
|
2612 numqualifier = " %s [+]" % optlabel |
|
2613 multioccur = True |
|
2614 elif (default is not None) and not isinstance(default, bool): |
|
2615 numqualifier = " %s" % optlabel |
|
2616 else: |
|
2617 numqualifier = "" |
|
2618 out.append(("%2s%s" % |
|
2619 (shortopt and "-%s" % shortopt, |
|
2620 longopt and " --%s%s" % |
|
2621 (longopt, numqualifier)), |
|
2622 "%s%s" % (desc, |
|
2623 default |
|
2624 and _(" (default: %s)") % default |
|
2625 or ""))) |
|
2626 if multioccur: |
|
2627 msg = _("\n[+] marked option can be specified multiple times") |
|
2628 if ui.verbose and name != 'shortlist': |
|
2629 out.append((msg, None)) |
|
2630 else: |
|
2631 out.insert(-1, (msg, None)) |
|
2632 |
|
2633 text = "" |
|
2634 if out: |
|
2635 colwidth = encoding.colwidth |
|
2636 # normalize: (opt or message, desc or None, width of opt) |
|
2637 entries = [desc and (opt, desc, colwidth(opt)) or (opt, None, 0) |
|
2638 for opt, desc in out] |
|
2639 hanging = max([e[2] for e in entries]) |
|
2640 for opt, desc, width in entries: |
|
2641 if desc: |
|
2642 initindent = ' %s%s ' % (opt, ' ' * (hanging - width)) |
|
2643 hangindent = ' ' * (hanging + 3) |
|
2644 text += '%s\n' % (util.wrap(desc, width, |
|
2645 initindent=initindent, |
|
2646 hangindent=hangindent)) |
|
2647 else: |
|
2648 text += "%s\n" % opt |
|
2649 |
|
2650 return text |
2594 |
2651 |
2595 def addglobalopts(aliases): |
2652 def addglobalopts(aliases): |
2596 if ui.verbose: |
2653 if ui.verbose: |
2597 optlist.append((_("global options:"), globalopts)) |
2654 optlist.append((_("global options:"), globalopts)) |
2598 if name == 'shortlist': |
2655 if name == 'shortlist': |
2827 topics.append((sorted(names, key=len, reverse=True)[0], header)) |
2884 topics.append((sorted(names, key=len, reverse=True)[0], header)) |
2828 topics_len = max([len(s[0]) for s in topics]) |
2885 topics_len = max([len(s[0]) for s in topics]) |
2829 for t, desc in topics: |
2886 for t, desc in topics: |
2830 ui.write(" %-*s %s\n" % (topics_len, t, desc)) |
2887 ui.write(" %-*s %s\n" % (topics_len, t, desc)) |
2831 |
2888 |
2832 # list all option lists |
2889 ui.write(opttext(optlist, textwidth)) |
2833 opt_output = [] |
|
2834 multioccur = False |
|
2835 for title, options in optlist: |
|
2836 opt_output.append(("\n%s" % title, None)) |
|
2837 for option in options: |
|
2838 if len(option) == 5: |
|
2839 shortopt, longopt, default, desc, optlabel = option |
|
2840 else: |
|
2841 shortopt, longopt, default, desc = option |
|
2842 optlabel = _("VALUE") # default label |
|
2843 |
|
2844 if _("DEPRECATED") in desc and not ui.verbose: |
|
2845 continue |
|
2846 if isinstance(default, list): |
|
2847 numqualifier = " %s [+]" % optlabel |
|
2848 multioccur = True |
|
2849 elif (default is not None) and not isinstance(default, bool): |
|
2850 numqualifier = " %s" % optlabel |
|
2851 else: |
|
2852 numqualifier = "" |
|
2853 opt_output.append(("%2s%s" % |
|
2854 (shortopt and "-%s" % shortopt, |
|
2855 longopt and " --%s%s" % |
|
2856 (longopt, numqualifier)), |
|
2857 "%s%s" % (desc, |
|
2858 default |
|
2859 and _(" (default: %s)") % default |
|
2860 or ""))) |
|
2861 if multioccur: |
|
2862 msg = _("\n[+] marked option can be specified multiple times") |
|
2863 if ui.verbose and name != 'shortlist': |
|
2864 opt_output.append((msg, None)) |
|
2865 else: |
|
2866 opt_output.insert(-1, (msg, None)) |
|
2867 |
|
2868 if opt_output: |
|
2869 colwidth = encoding.colwidth |
|
2870 # normalize: (opt or message, desc or None, width of opt) |
|
2871 entries = [desc and (opt, desc, colwidth(opt)) or (opt, None, 0) |
|
2872 for opt, desc in opt_output] |
|
2873 hanging = max([e[2] for e in entries]) |
|
2874 for opt, desc, width in entries: |
|
2875 if desc: |
|
2876 initindent = ' %s%s ' % (opt, ' ' * (hanging - width)) |
|
2877 hangindent = ' ' * (hanging + 3) |
|
2878 ui.write('%s\n' % (util.wrap(desc, textwidth, |
|
2879 initindent=initindent, |
|
2880 hangindent=hangindent))) |
|
2881 else: |
|
2882 ui.write("%s\n" % opt) |
|
2883 |
2890 |
2884 @command('identify|id', |
2891 @command('identify|id', |
2885 [('r', 'rev', '', |
2892 [('r', 'rev', '', |
2886 _('identify the specified revision'), _('REV')), |
2893 _('identify the specified revision'), _('REV')), |
2887 ('n', 'num', None, _('show local revision number')), |
2894 ('n', 'num', None, _('show local revision number')), |