'The guts of the command-line parser.'

def parseOptions(self, options=None):

    if (options is None):
        options = sys.argv[1:]
    if ((len(options) > 1) and (options[(-2)] == '--_shell-completion')):
        from twisted.python import _shellcomp
        cmdName = path.basename(sys.argv[0])
        _shellcomp.shellComplete(self, cmdName, options, self._shellCompFile)
        sys.exit(0)
    try:
        (opts, args) = getopt.getopt(options, self.shortOpt, self.longOpt)
    except getopt.error as e:
        raise UsageError(str(e))
    for (opt, arg) in opts:
        if (opt[1] == '-'):
            opt = opt[2:]
        else:
            opt = opt[1:]
        optMangled = opt
        if (optMangled not in self.synonyms):
            optMangled = opt.replace('-', '_')
            if (optMangled not in self.synonyms):
                raise UsageError(("No    such    option    '%s'" % (opt,)))
        optMangled = self.synonyms[optMangled]
        if isinstance(self._dispatch[optMangled], CoerceParameter):
            self._dispatch[optMangled].dispatch(optMangled, arg)
        else:
            self._dispatch[optMangled](optMangled, arg)
    if (getattr(self, 'subCommands', None) and (args or (self.defaultSubCommand is not None))):
        if (not args):
            args = [self.defaultSubCommand]
        (sub, rest) = (args[0], args[1:])
        for (cmd, short, parser, doc) in self.subCommands:
            if ((sub == cmd) or (sub == short)):
                self.subCommand = cmd
                self.subOptions = parser()
                self.subOptions.parent = self
                self.subOptions.parseOptions(rest)
                break
        else:
            raise UsageError(('Unknown    command:    %s' % sub))
    else:
        try:
            self.parseArgs(*args)
        except TypeError:
            raise UsageError('Wrong    number    of    arguments.')
    self.postOptions()
