Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/commands.py @ 31079:2a0c8e3636b0
help: move rst formatting of help documents into help.py
This slight refactor will help me improve the 'unknown command'
experience in our new glorious pager future.
author | Augie Fackler <augie@google.com> |
---|---|
date | Tue, 21 Feb 2017 14:17:31 -0500 |
parents | d2ed0abce08e |
children | be74ce1b930f |
comparison
equal
deleted
inserted
replaced
31078:d2ed0abce08e | 31079:2a0c8e3636b0 |
---|---|
37 hbisect, | 37 hbisect, |
38 help, | 38 help, |
39 hg, | 39 hg, |
40 lock as lockmod, | 40 lock as lockmod, |
41 merge as mergemod, | 41 merge as mergemod, |
42 minirst, | |
43 obsolete, | 42 obsolete, |
44 patch, | 43 patch, |
45 phases, | 44 phases, |
46 pycompat, | 45 pycompat, |
47 revsetlang, | 46 revsetlang, |
2719 Given a topic, extension, or command name, print help for that | 2718 Given a topic, extension, or command name, print help for that |
2720 topic. | 2719 topic. |
2721 | 2720 |
2722 Returns 0 if successful. | 2721 Returns 0 if successful. |
2723 """ | 2722 """ |
2724 textwidth = ui.configint('ui', 'textwidth', 78) | |
2725 termwidth = ui.termwidth() - 2 | |
2726 if textwidth <= 0 or termwidth < textwidth: | |
2727 textwidth = termwidth | |
2728 | 2723 |
2729 keep = opts.get('system') or [] | 2724 keep = opts.get('system') or [] |
2730 if len(keep) == 0: | 2725 if len(keep) == 0: |
2731 if pycompat.sysplatform.startswith('win'): | 2726 if pycompat.sysplatform.startswith('win'): |
2732 keep.append('windows') | 2727 keep.append('windows') |
2738 keep.append('unix') | 2733 keep.append('unix') |
2739 keep.append(pycompat.sysplatform.lower()) | 2734 keep.append(pycompat.sysplatform.lower()) |
2740 if ui.verbose: | 2735 if ui.verbose: |
2741 keep.append('verbose') | 2736 keep.append('verbose') |
2742 | 2737 |
2743 fullname = name | 2738 formatted = help.formattedhelp(ui, name, keep=keep, **opts) |
2744 section = None | |
2745 subtopic = None | |
2746 if name and '.' in name: | |
2747 name, remaining = name.split('.', 1) | |
2748 remaining = encoding.lower(remaining) | |
2749 if '.' in remaining: | |
2750 subtopic, section = remaining.split('.', 1) | |
2751 else: | |
2752 if name in help.subtopics: | |
2753 subtopic = remaining | |
2754 else: | |
2755 section = remaining | |
2756 | |
2757 text = help.help_(ui, name, subtopic=subtopic, **opts) | |
2758 | |
2759 formatted, pruned = minirst.format(text, textwidth, keep=keep, | |
2760 section=section) | |
2761 | |
2762 # We could have been given a weird ".foo" section without a name | |
2763 # to look for, or we could have simply failed to found "foo.bar" | |
2764 # because bar isn't a section of foo | |
2765 if section and not (formatted and name): | |
2766 raise error.Abort(_("help section not found: %s") % fullname) | |
2767 | |
2768 if 'verbose' in pruned: | |
2769 keep.append('omitted') | |
2770 else: | |
2771 keep.append('notomitted') | |
2772 formatted, pruned = minirst.format(text, textwidth, keep=keep, | |
2773 section=section) | |
2774 ui.pager('help') | 2739 ui.pager('help') |
2775 ui.write(formatted) | 2740 ui.write(formatted) |
2776 | 2741 |
2777 | 2742 |
2778 @command('identify|id', | 2743 @command('identify|id', |