Mercurial > public > mercurial-scm > hg
comparison mercurial/commands.py @ 16818:d0fc1e689227
help: format command help using RST
author | Olav Reinert <seroton10@gmail.com> |
---|---|
date | Fri, 01 Jun 2012 12:35:30 +0200 |
parents | 946800b43533 |
children | af69b2b64d6e |
comparison
equal
deleted
inserted
replaced
16817:946800b43533 | 16818:d0fc1e689227 |
---|---|
3104 if getattr(entry[0], 'badalias', False): | 3104 if getattr(entry[0], 'badalias', False): |
3105 if not unknowncmd: | 3105 if not unknowncmd: |
3106 entry[0](ui) | 3106 entry[0](ui) |
3107 return | 3107 return |
3108 | 3108 |
3109 rst = "" | 3109 rst = [] |
3110 | 3110 |
3111 # synopsis | 3111 # synopsis |
3112 if len(entry) > 2: | 3112 if len(entry) > 2: |
3113 if entry[2].startswith('hg'): | 3113 if entry[2].startswith('hg'): |
3114 rst += "%s\n" % entry[2] | 3114 rst.append("%s\n" % entry[2]) |
3115 else: | 3115 else: |
3116 rst += 'hg %s %s\n' % (aliases[0], entry[2]) | 3116 rst.append('hg %s %s\n' % (aliases[0], entry[2])) |
3117 else: | 3117 else: |
3118 rst += 'hg %s\n' % aliases[0] | 3118 rst.append('hg %s\n' % aliases[0]) |
3119 | |
3120 # aliases | 3119 # aliases |
3121 if full and not ui.quiet and len(aliases) > 1: | 3120 if full and not ui.quiet and len(aliases) > 1: |
3122 rst += _("\naliases: %s\n") % ', '.join(aliases[1:]) | 3121 rst.append(_("\naliases: %s\n") % ', '.join(aliases[1:])) |
3122 rst.append('\n') | |
3123 | 3123 |
3124 # description | 3124 # description |
3125 doc = gettext(entry[0].__doc__) | 3125 doc = gettext(entry[0].__doc__) |
3126 if not doc: | 3126 if not doc: |
3127 doc = _("(no help text available)") | 3127 doc = _("(no help text available)") |
3128 if util.safehasattr(entry[0], 'definition'): # aliased command | 3128 if util.safehasattr(entry[0], 'definition'): # aliased command |
3129 if entry[0].definition.startswith('!'): # shell alias | 3129 if entry[0].definition.startswith('!'): # shell alias |
3130 doc = _('shell alias for::\n\n %s') % entry[0].definition[1:] | 3130 doc = _('shell alias for::\n\n %s') % entry[0].definition[1:] |
3131 else: | 3131 else: |
3132 doc = _('alias for: hg %s\n\n%s') % (entry[0].definition, doc) | 3132 doc = _('alias for: hg %s\n\n%s') % (entry[0].definition, doc) |
3133 doc = doc.splitlines(True) | |
3133 if ui.quiet or not full: | 3134 if ui.quiet or not full: |
3134 doc = doc.splitlines()[0] | 3135 rst.append(doc[0]) |
3135 rst += "\n" + doc + "\n" | 3136 else: |
3137 rst.extend(doc) | |
3138 rst.append('\n') | |
3136 | 3139 |
3137 # check if this command shadows a non-trivial (multi-line) | 3140 # check if this command shadows a non-trivial (multi-line) |
3138 # extension help text | 3141 # extension help text |
3139 try: | 3142 try: |
3140 mod = extensions.find(name) | 3143 mod = extensions.find(name) |
3141 doc = gettext(mod.__doc__) or '' | 3144 doc = gettext(mod.__doc__) or '' |
3142 if '\n' in doc.strip(): | 3145 if '\n' in doc.strip(): |
3143 msg = _('use "hg help -e %s" to show help for ' | 3146 msg = _('use "hg help -e %s" to show help for ' |
3144 'the %s extension') % (name, name) | 3147 'the %s extension') % (name, name) |
3145 rst += '\n%s\n' % msg | 3148 rst.append('\n%s\n' % msg) |
3146 except KeyError: | 3149 except KeyError: |
3147 pass | 3150 pass |
3148 | 3151 |
3149 # options | 3152 # options |
3150 if not ui.quiet and entry[1]: | 3153 if not ui.quiet and entry[1]: |
3151 rst += '\n' | 3154 rst.append('\n%s\n\n' % _("options:")) |
3152 rst += _("options:") | 3155 rst.append(help.optrst(entry[1], ui.verbose)) |
3153 rst += '\n\n' | |
3154 rst += help.optrst(entry[1], ui.verbose) | |
3155 | 3156 |
3156 if ui.verbose: | 3157 if ui.verbose: |
3157 rst += '\n' | 3158 rst.append('\n%s\n\n' % _("global options:")) |
3158 rst += _("global options:") | 3159 rst.append(help.optrst(globalopts, ui.verbose)) |
3159 rst += '\n\n' | |
3160 rst += help.optrst(globalopts, ui.verbose) | |
3161 | |
3162 keep = ui.verbose and ['verbose'] or [] | |
3163 formatted, pruned = minirst.format(rst, textwidth, keep=keep) | |
3164 ui.write(formatted) | |
3165 | 3160 |
3166 if not ui.verbose: | 3161 if not ui.verbose: |
3167 if not full: | 3162 if not full: |
3168 ui.write(_('\nuse "hg help %s" to show the full help text\n') | 3163 rst.append(_('\nuse "hg help %s" to show the full help text\n') |
3169 % name) | 3164 % name) |
3170 elif not ui.quiet: | 3165 elif not ui.quiet: |
3171 ui.write(_('\nuse "hg -v help %s" to show more info\n') % name) | 3166 rst.append(_('\nuse "hg -v help %s" to show more info\n') |
3167 % name) | |
3168 | |
3169 keep = ui.verbose and ['verbose'] or [] | |
3170 formatted, pruned = minirst.format(''.join(rst), textwidth, keep=keep) | |
3171 ui.write(formatted) | |
3172 | 3172 |
3173 | 3173 |
3174 def helplist(select=None): | 3174 def helplist(select=None): |
3175 # list of commands | 3175 # list of commands |
3176 if name == "shortlist": | 3176 if name == "shortlist": |