Mercurial > public > mercurial-scm > hg
diff mercurial/fancyopts.py @ 43076:2372284d9457
formatting: blacken the codebase
This is using my patch to black
(https://github.com/psf/black/pull/826) so we don't un-wrap collection
literals.
Done with:
hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**"' | xargs black -S
# skip-blame mass-reformatting only
# no-check-commit reformats foo_bar functions
Differential Revision: https://phab.mercurial-scm.org/D6971
author | Augie Fackler <augie@google.com> |
---|---|
date | Sun, 06 Oct 2019 09:45:02 -0400 |
parents | 39e5e346eba7 |
children | 687b865b95ad |
line wrap: on
line diff
--- a/mercurial/fancyopts.py Sat Oct 05 10:29:34 2019 -0400 +++ b/mercurial/fancyopts.py Sun Oct 06 09:45:02 2019 -0400 @@ -27,6 +27,7 @@ 'version', } + def _earlyoptarg(arg, shortlist, namelist): """Check if the given arg is a valid unabbreviated option @@ -89,6 +90,7 @@ return flag, bool(val), val, shortlist.startswith(':', i + 1) return '', False, '', False + def earlygetopt(args, shortlist, namelist, gnu=False, keepsep=False): """Parse options like getopt, but ignores unknown options and abbreviated forms @@ -202,6 +204,7 @@ parsedargs.extend(args[pos:]) return parsedopts, parsedargs + class customopt(object): """Manage defaults and mutations for any type of opt.""" @@ -226,6 +229,7 @@ On failure, abort can be called with a string error message.""" + class _simpleopt(customopt): def _isboolopt(self): return isinstance(self._defaultvalue, (bool, type(None))) @@ -233,6 +237,7 @@ def newstate(self, oldstate, newparam, abort): return newparam + class _callableopt(customopt): def __init__(self, callablefn): self.callablefn = callablefn @@ -241,6 +246,7 @@ def newstate(self, oldstate, newparam, abort): return self.callablefn(newparam) + class _listopt(customopt): def getdefaultvalue(self): return self._defaultvalue[:] @@ -249,6 +255,7 @@ oldstate.append(newparam) return oldstate + class _intopt(customopt): def newstate(self, oldstate, newparam, abort): try: @@ -256,6 +263,7 @@ except ValueError: abort(_('expected int')) + def _defaultopt(default): """Returns a default opt implementation, given a default value.""" @@ -270,6 +278,7 @@ else: return _simpleopt(default) + def fancyopts(args, options, state, gnu=False, early=False, optaliases=None): """ read args, parse options, and store options in state @@ -369,9 +378,13 @@ if obj._isboolopt(): state[name] = boolval else: + def abort(s): - raise error.Abort(_('invalid value %r for option %s, %s') - % (pycompat.maybebytestr(val), opt, s)) + raise error.Abort( + _('invalid value %r for option %s, %s') + % (pycompat.maybebytestr(val), opt, s) + ) + state[name] = defmap[name].newstate(state[name], val, abort) # return unparsed args