[PATCH 2 of 3] flags: allow specifying --boolean-flag=(true|false) on the command line (BC)

Augie Fackler raf at durin42.com
Thu Aug 18 12:13:33 EDT 2016


# HG changeset patch
# User Augie Fackler <augie at google.com>
# Date 1471534453 14400
#      Thu Aug 18 11:34:13 2016 -0400
# Node ID 9ec3aad0bf74ad1c25e87bcd0f536896d1c355ca
# Parent  8ed7fdc716ffc95a4062875eafc2739697122fbc
flags: allow specifying --boolean-flag=(true|false) on the command line (BC)

This makes it much easier to enable some anti-foot-shooting features
(like update --check) by default, because now all boolean flags can be
explicitly disabled on the command line without having to use HGPLAIN
or similar.

diff --git a/mercurial/fancyopts.py b/mercurial/fancyopts.py
--- a/mercurial/fancyopts.py
+++ b/mercurial/fancyopts.py
@@ -10,7 +10,10 @@ from __future__ import absolute_import
 import getopt
 
 from .i18n import _
-from . import error
+from . import (
+    error,
+    util,
+)
 
 def gnugetopt(args, options, longoptions):
     """Parse options mostly like getopt.gnu_getopt.
@@ -91,6 +94,10 @@ def fancyopts(args, options, state, gnu=
                 short += ':'
             if oname:
                 oname += '='
+        else:
+            prefix = '--' + oname + '='
+            if any(a.startswith(prefix) for a in args):
+                oname += '='
         if short:
             shortlist += short
         if name:
@@ -121,7 +128,10 @@ def fancyopts(args, options, state, gnu=
         elif t is type([]):
             state[name].append(val)
         elif t is type(None) or t is type(False):
-            state[name] = True
+            if val:
+                state[name] = util.parsebool(val)
+            else:
+                state[name] = True
 
     # return unparsed args
     return args
diff --git a/tests/test-update-branches.t b/tests/test-update-branches.t
--- a/tests/test-update-branches.t
+++ b/tests/test-update-branches.t
@@ -379,3 +379,14 @@ Test experimental revset support
 
   $ hg log -r '_destupdate()'
   2:bd10386d478c 2 (no-eol)
+
+Test that boolean flags allow --flag=false specification to override [defaults]
+  $ cat >> $HGRCPATH <<EOF
+  > [defaults]
+  > update = --check
+  > EOF
+  $ hg co 2
+  abort: uncommitted changes
+  [255]
+  $ hg co --check=no 2
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved


More information about the Mercurial-devel mailing list