'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.'

def parse(self, args):

    try:
        (flags, extra) = self.optfunc(args, self._shortopts, self._longopts)
    except getopt.GetoptError as e:
        self.fatal(e)
    opt = OptDict()
    for (k, v) in self._defaults.items():
        k = self._aliases[k]
        opt[k] = v
    for (k, v) in flags:
        k = k.lstrip('-')
        if (k in ('h', '?', 'help')):
            self.usage()
        if k.startswith('no-'):
            k = self._aliases[k[3:]]
            v = 0
        else:
            k = self._aliases[k]
            if (not self._hasparms[k]):
                assert (v == '')
                v = ((opt._opts.get(k) or 0) + 1)
            else:
                v = _intify(v)
        opt[k] = v
    for (f1, f2) in self._aliases.items():
        opt[f1] = opt._opts.get(f2)
    return (opt, flags, extra)
