diff mercurial/help.py @ 30026: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
line wrap: on
line diff
--- a/mercurial/help.py	Tue Sep 27 14:46:34 2016 +0200
+++ b/mercurial/help.py	Tue Sep 13 22:58:12 2016 -0400
@@ -20,6 +20,7 @@
     encoding,
     error,
     extensions,
+    fancyopts,
     filemerge,
     fileset,
     minirst,
@@ -65,6 +66,7 @@
 def optrst(header, options, verbose):
     data = []
     multioccur = False
+    alllong = set(o[1] for o in options)
     for option in options:
         if len(option) == 5:
             shortopt, longopt, default, desc, optlabel = option
@@ -87,6 +89,16 @@
             multioccur = True
         elif (default is not None) and not isinstance(default, bool):
             lo += " %s" % optlabel
+        elif longopt not in fancyopts.nevernegate:
+            if longopt.startswith('no-'):
+                # This odd if statement guards against showing
+                # --no-commit and --commit on backout (as a practical
+                # example) as --[no-]commit in help.
+                if (longopt[3:]) not in alllong:
+                    lo = '--[no-]' + lo[5:]
+            else:
+                if ('no-' + longopt) not in alllong:
+                    lo = '--[no-]' + lo[2:]
 
         data.append((so, lo, desc))