On Thu, 18 Aug 2016 12:13:33 -0400, Augie Fackler wrote:
> # HG changeset patch
> # User Augie Fackler <au...@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.

I understand this will be somewhat useful, but I'm not a big fan of introducing
less common parsing rules.

> --- 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 += '='

args may contain a value looks like --option=.

  $ hg up -t --check=false --check

> -            state[name] = True
> +            if val:
> +                state[name] = util.parsebool(val)

this should abort if val isn't a boolean literal.

> --- 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

Perhaps this would be parsed as --check '--check=no'.
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to