Mercurial > hg
comparison mercurial/commands.py @ 16853:7863ff383894
help: format command and option list help using RST
This patch changes the function which generates help text about commands and
options to use RST formatting. Tables describing options have been formatted
using RST table markup for some time already, so their appearance does not
change. Command lists, however, change appearance.
To format non-verbose command lists, RST field list markup was chosen, because
it resembles the old format:
<http://docutils.sourceforge.net/docs/user/rst/quickref.html#field-lists>
In the old (hand-coded) format of non-verbose command lists, the left column is
12 characters wide. Our minirst implementation formats field lists with a left
column 14 characters wide, so this patch changes the appearance of help output
correspondingly:
<http://markmail.org/message/krl4cxopsnii7s6z?q=mercurial+reinert+from:%22Olav+Reinert%22&page=2>
The minirst markup most closely resembling the old verbose command lists is
definition lists. But using it would cause a blank line to be inserted between
each command definition, making the output excessively long, and no more
useful than before. To avoid this, I chose to use field lists also for verbose
command help, resulting in output like this example:
add add the specified files on the next commit
annotate, blame
show changeset information by line for each file
clone make a copy of an existing repository
commit, ci commit the specified files or all outstanding changes
diff diff repository (or selected files)
export dump the header and diffs for one or more changesets
forget forget the specified files on the next commit
init create a new repository in the given directory
log, history show revision history of entire repository or files
merge merge working directory with another revision
phase set or show the current phase name
pull pull changes from the specified source
push push changes to the specified destination
qdiff diff of the current patch and subsequent modifications
qinit init a new queue repository (DEPRECATED)
qnew create a new patch
qpop pop the current patch off the stack
qpush push the next patch onto the stack
qrefresh update the current patch
remove, rm remove the specified files on the next commit
serve start stand-alone webserver
status, st show changed files in the working directory
summary, sum summarize working directory state
update, up, checkout, co
update working directory (or switch revisions)
This change is a move towards generating all help text as a list of strings
marked up with RST.
author | Olav Reinert <seroton10@gmail.com> |
---|---|
date | Sat, 02 Jun 2012 11:25:40 +0200 |
parents | af69b2b64d6e |
children | d71ada5a6a33 |
comparison
equal
deleted
inserted
replaced
16852:af69b2b64d6e | 16853:7863ff383894 |
---|---|
3203 | 3203 |
3204 if not h: | 3204 if not h: |
3205 ui.status(_('no commands defined\n')) | 3205 ui.status(_('no commands defined\n')) |
3206 return | 3206 return |
3207 | 3207 |
3208 ui.status(header) | 3208 rst = [] |
3209 if not ui.quiet: | |
3210 rst.append(header) | |
3209 fns = sorted(h) | 3211 fns = sorted(h) |
3210 m = max(map(len, fns)) | |
3211 for f in fns: | 3212 for f in fns: |
3212 if ui.verbose: | 3213 if ui.verbose: |
3213 commands = cmds[f].replace("|",", ") | 3214 commands = cmds[f].replace("|",", ") |
3214 ui.write(" %s:\n %s\n"%(commands, h[f])) | 3215 rst.append(" :%s: %s\n" % (commands, h[f])) |
3215 else: | 3216 else: |
3216 ui.write('%s\n' % (util.wrap(h[f], textwidth, | 3217 rst.append(' :%s: %s\n' % (f, h[f])) |
3217 initindent=' %-*s ' % (m, f), | |
3218 hangindent=' ' * (m + 4)))) | |
3219 | 3218 |
3220 if not name: | 3219 if not name: |
3221 rst = help.listexts(_('enabled extensions:'), extensions.enabled()) | 3220 exts = help.listexts(_('enabled extensions:'), extensions.enabled()) |
3222 if rst: | 3221 if exts: |
3223 ui.write("\n%s" % minirst.format('\n'.join(rst), textwidth)) | 3222 rst.append('\n') |
3224 | 3223 rst.extend(exts) |
3225 ui.write(_("\nadditional help topics:\n\n")) | 3224 |
3225 rst.append(_("\nadditional help topics:\n\n")) | |
3226 topics = [] | 3226 topics = [] |
3227 for names, header, doc in help.helptable: | 3227 for names, header, doc in help.helptable: |
3228 topics.append((sorted(names, key=len, reverse=True)[0], header)) | 3228 topics.append((sorted(names, key=len, reverse=True)[0], header)) |
3229 topics_len = max([len(s[0]) for s in topics]) | |
3230 for t, desc in topics: | 3229 for t, desc in topics: |
3231 ui.write(" %-*s %s\n" % (topics_len, t, desc)) | 3230 rst.append(" :%s: %s\n" % (t, desc)) |
3232 | 3231 |
3233 optlist = [] | 3232 optlist = [] |
3234 if not ui.quiet: | 3233 if not ui.quiet: |
3235 if ui.verbose: | 3234 if ui.verbose: |
3236 optlist.append((_("global options:"), globalopts)) | 3235 optlist.append((_("global options:"), globalopts)) |
3247 else: | 3246 else: |
3248 msg = _('use "hg -v help%s" to show builtin aliases and ' | 3247 msg = _('use "hg -v help%s" to show builtin aliases and ' |
3249 'global options') % (name and " " + name or "") | 3248 'global options') % (name and " " + name or "") |
3250 optlist.append((msg, ())) | 3249 optlist.append((msg, ())) |
3251 | 3250 |
3252 if not optlist: | 3251 if optlist: |
3253 return | 3252 for title, options in optlist: |
3254 | 3253 rst.append('\n%s\n' % title) |
3255 rst = '' | 3254 if options: |
3256 for title, options in optlist: | 3255 rst.append('\n%s\n' % help.optrst(options, ui.verbose)) |
3257 rst += '\n%s\n' % title | 3256 ui.write(minirst.format(''.join(rst), textwidth)) |
3258 if options: | |
3259 rst += "\n" | |
3260 rst += help.optrst(options, ui.verbose) | |
3261 rst += '\n' | |
3262 ui.write('\n' + minirst.format(rst, textwidth)) | |
3263 | 3257 |
3264 def helptopic(name): | 3258 def helptopic(name): |
3265 for names, header, doc in help.helptable: | 3259 for names, header, doc in help.helptable: |
3266 if name in names: | 3260 if name in names: |
3267 break | 3261 break |