Skip to content
Myr

Further simplified internal parser API

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Armin Ronacher · committed by Armin Ronacher · parent a4a5986 · Browse files · 1 file+8 added−19 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+8 added−19 removed

  • other:+8 added−19 removed

1 file+8 added−19 removed

modified:click/parser.py+8 added-19 removed
18 unmodified lines
19from .utils import unpack_args202122class Option(object):23 ATTRS = ('action', 'type', 'dest', 'nargs', 'const')24 TYPED_ACTIONS = ('store', 'append')25 TAKES_VALUE_ACTIONS = ('store', 'append')2327 def __init__(self, opts, **attrs):24 def __init__(self, opts, dest, action=None, nargs=1, const=None):25 self._short_opts = []26 self._long_opts = []2728 for opt in opts:
1 unmodified line
30 self._long_opts.append(opt)31 elif opt[:1] == '-':32 self._short_opts.append(opt)3337 for attr in self.ATTRS:38 if attr in attrs:39 setattr(self, attr, attrs.pop(attr))40 else:41 setattr(self, attr, None)34 if action is None:35 action = 'store'3643 if attrs:44 attrs = sorted(attrs.keys())45 raise TypeError('invalid keyword arguments: %s' % ', '.join(attrs))37 self.dest = dest38 self.action = action39 self.nargs = nargs40 self.const = const4147 if self.action is None:48 self.action = 'store'49 if self.action in self.TYPED_ACTIONS:50 if self.nargs is None:51 self.nargs = 15242 @property43 def takes_value(self):55 return self.action in self.TAKES_VALUE_ACTIONS44 return self.action in ('store', 'append')4546 def process(self, opt, value, opts, parser):47 if self.action == 'store':48 opts[self.dest] = value
188 unmodified lines