D2090: fancyopts: add support for custom multi-arg opts in fancyopts.py

durin42 (Augie Fackler) phabricator at mercurial-scm.org
Wed Feb 21 22:27:39 EST 2018


durin42 added a comment.


  In https://phab.mercurial-scm.org/D2090#39120, @dploch wrote:
  
  > In https://phab.mercurial-scm.org/D2090#38775, @indygreg wrote:
  >
  > > Out of curiosity, do you think it would be possible to implement an option that behaved like a boolean when given in isolation but also optionally accepted a value? My use case is I want `hg serve --open` to automatically open a web browser pointing at the started server and `hg serve --open chrome` to open Chrome instead of my default web browser. I'm not sure if that's a good idea to implement in the parser though. It could possibly lead to ambiguous argument parsing.
  >
  >
  > It feels like a bad idea.  If we want the parsing to be unambiguous, then '--open' must always come at the end of the command line if the default option is desired.  If there were a separate flag with the same semantics, you couldn't specify both:  'hg serve --open --foo' would pass "--foo" as the argument to --open.
  >
  > If we stipulate that the optional argument only counts as an argument if it doesn't look like a flag (^-(-)?[^\d-].*$), it sort of works, but that feels pretty messy.
  
  
  I agree, it's too hard to understand the parsing rules if we allow this. I actually explored this a bit with negating boolean flags and it's just Too Messy in my opinion.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D2090

To: dploch, #hg-reviewers, durin42, indygreg
Cc: durin42, indygreg, mercurial-devel


More information about the Mercurial-devel mailing list