comparison mercurial/help.py @ 30024:f3c4edfd35e1

help: mark boolean flags with [no-] to explain that they can be negated That is, help gets tweaked thus: global options ([+] can be repeated): -v --[no-]verbose enable additional output Other proposals have included: global options ([+] can be repeated, options marked [?] are boolean flags): -v --verbose[?] enable additional output and global options ([+] can be repeated, options marked [^] are boolean flags): -v --verbose[^] enable additional output which avoid the unfortunate visual noise in this patch. In this version's favor, it's consistent with what I'm used to seeing in man pages and similar documentation venues.
author Augie Fackler <augie@google.com>
date Tue, 13 Sep 2016 22:58:12 -0400
parents 7109d5ddeb0c
children d65e246100ed
comparison
equal deleted inserted replaced
30023:ff17dff99295 30024:f3c4edfd35e1
18 from . import ( 18 from . import (
19 cmdutil, 19 cmdutil,
20 encoding, 20 encoding,
21 error, 21 error,
22 extensions, 22 extensions,
23 fancyopts,
23 filemerge, 24 filemerge,
24 fileset, 25 fileset,
25 minirst, 26 minirst,
26 revset, 27 revset,
27 templatefilters, 28 templatefilters,
63 return doc 64 return doc
64 65
65 def optrst(header, options, verbose): 66 def optrst(header, options, verbose):
66 data = [] 67 data = []
67 multioccur = False 68 multioccur = False
69 alllong = set(o[1] for o in options)
68 for option in options: 70 for option in options:
69 if len(option) == 5: 71 if len(option) == 5:
70 shortopt, longopt, default, desc, optlabel = option 72 shortopt, longopt, default, desc, optlabel = option
71 else: 73 else:
72 shortopt, longopt, default, desc = option 74 shortopt, longopt, default, desc = option
85 if isinstance(default, list): 87 if isinstance(default, list):
86 lo += " %s [+]" % optlabel 88 lo += " %s [+]" % optlabel
87 multioccur = True 89 multioccur = True
88 elif (default is not None) and not isinstance(default, bool): 90 elif (default is not None) and not isinstance(default, bool):
89 lo += " %s" % optlabel 91 lo += " %s" % optlabel
92 elif longopt not in fancyopts.nevernegate:
93 if longopt.startswith('no-'):
94 # This odd if statement guards against showing
95 # --no-commit and --commit on backout (as a practical
96 # example) as --[no-]commit in help.
97 if (longopt[3:]) not in alllong:
98 lo = '--[no-]' + lo[5:]
99 else:
100 if ('no-' + longopt) not in alllong:
101 lo = '--[no-]' + lo[2:]
90 102
91 data.append((so, lo, desc)) 103 data.append((so, lo, desc))
92 104
93 if multioccur: 105 if multioccur:
94 header += (_(" ([+] can be repeated)")) 106 header += (_(" ([+] can be repeated)"))