Removed more optparse leftovers
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 97b505c · Browse files · 1 file·+9 added−28 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+9 added−28 removed
- other:+9 added−28 removed
Provenance
- Commit
75aeb7c- Tree
98c4b3c- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
97b505c
1 file changed+9 added−28 removed
modified:click/parser.py+9 added-28 removed
17 unmodified lines18 from .exceptions import UsageError19 20 21 class Option(object):22- ATTRS = ['action', 'type', 'dest', 'nargs', 'const', 'help',23- 'metavar']22+ ATTRS = ['action', 'type', 'dest', 'nargs', 'const']23 ACTIONS = ('store', 'store_const', 'append', 'append_const')24 STORE_ACTIONS = ('store', 'store_const', 'append', 'append_const')25 TYPED_ACTIONS = ('store', 'append')26 TAKES_VALUE_ACTIONS = ('store', 'append')3 unmodified lines30 self._short_opts = []31 self._long_opts = []32 33 for opt in opts:35- if len(opt) < 2:36- raise TypeError(37- 'invalid option string %r: '38- 'must be at least two characters long' % opt)39- elif len(opt) == 2:40- if not (opt[0] == '-' and opt[1] != '-'):41- raise TypeError(42- 'invalid short option string %r: '43- 'must be of the form -x, (x any non-dash char)' % opt)44- self._short_opts.append(opt)45- else:46- if not (opt[:2] == '--' and opt[2] != '-'):47- raise TypeError(48- 'invalid long option string %r: '49- 'must start with --, followed by non-dash' % opt)34+ if opt[:2] == '--':35 self._long_opts.append(opt)36+ elif opt[:1] == '-':37+ self._short_opts.append(opt)38 39 for attr in self.ATTRS:40 if attr in attrs:41 setattr(self, attr, attrs[attr])1 unmodified line43 else:44 setattr(self, attr, None)45 if attrs:46 attrs = sorted(attrs.keys())60- raise TypeError('invalid keyword arguments: %s' %61- ', '.join(attrs))47+ raise TypeError('invalid keyword arguments: %s' % ', '.join(attrs))48 49 if self.action is None:50 self.action = 'store'51 if self.action in self.TYPED_ACTIONS:3 unmodified lines55 @property56 def takes_value(self):57 return self.action in self.TAKES_VALUE_ACTIONS58 73- def get_opt_string(self):74- if self._long_opts:75- return self._long_opts[0]76- return self._short_opts[0]77-59 def process(self, opt, value, opts, parser):60 if self.action == 'store':61 opts[self.dest] = value62 elif self.action == 'store_const':138 unmodified lines201 self.error('%s option requires %d arguments' % (opt, nargs))202 elif nargs == 1:203 value = rargs.pop(0)204 else:224- value = tuple(rargs[0:nargs])225- del rargs[0:nargs]205+ value = tuple(rargs[:nargs])206+ del rargs[:nargs]207 208 elif had_explicit_value:209 self.error('%s option does not take a value' % opt)210 29 unmodified lines240 (opt, nargs))241 elif nargs == 1:242 value = rargs.pop(0)243 else:263- value = tuple(rargs[0:nargs])264- del rargs[0:nargs]244+ value = tuple(rargs[:nargs])245+ del rargs[:nargs]246 247 else:248 value = None249 7 unmodified lines