MCPcopy Create free account
hub / github.com/apenwarr/sshuttle / parse

Method parse

options.py:165–200  ·  view source on GitHub ↗

Parse a list of arguments and return (options, flags, extra). In the returned tuple, "options" is an OptDict with known options, "flags" is a list of option flags that were used on the command-line, and "extra" is a list of positional arguments.

(self, args)

Source from the content-addressed store, hash-verified

163 return self.usage(msg)
164
165 def parse(self, args):
166 """Parse a list of arguments and return (options, flags, extra).
167
168 In the returned tuple, "options" is an OptDict with known options,
169 "flags" is a list of option flags that were used on the command-line,
170 and "extra" is a list of positional arguments.
171 """
172 try:
173 (flags,extra) = self.optfunc(args, self._shortopts, self._longopts)
174 except getopt.GetoptError, e:
175 self.fatal(e)
176
177 opt = OptDict()
178
179 for k,v in self._defaults.iteritems():
180 k = self._aliases[k]
181 opt[k] = v
182
183 for (k,v) in flags:
184 k = k.lstrip('-')
185 if k in ('h', '?', 'help'):
186 self.usage()
187 if k.startswith('no-'):
188 k = self._aliases[k[3:]]
189 v = 0
190 else:
191 k = self._aliases[k]
192 if not self._hasparms[k]:
193 assert(v == '')
194 v = (opt._opts.get(k) or 0) + 1
195 else:
196 v = _intify(v)
197 opt[k] = v
198 for (f1,f2) in self._aliases.iteritems():
199 opt[f1] = opt._opts.get(f2)
200 return (opt,flags,extra)

Callers 1

main.pyFile · 0.80

Calls 4

fatalMethod · 0.95
usageMethod · 0.95
OptDictClass · 0.85
_intifyFunction · 0.85

Tested by

no test coverage detected