Beispiel #1
0
    def run(self, ctx):
        cmd_args = ctx.cmd_opts
        if len(cmd_args) < 1:
            print get_simple_usage()
            return

        # Parse the options for help command itself
        cmd_name = None
        help_args = []
        if not cmd_args[0].startswith('-'):
            cmd_name = cmd_args[0]
            cmd_args.pop(0)
        else:
            # eat all the help options
            _args = [cmd_args.pop(0)]
            while not _args[0].startswith('-') and len(cmd_args) > 0:
                _args.append(cmd_args.pop(0))
            help_args = _args
            cmd_name = cmd_args[0]

        # XXX: overkill as we don't support any options for now
        try:
            parser = OptionParser()
            for o in self.opts:
                parser.add_option(o)
            parser.parse_args(help_args)
        except OptionError, e:
            raise UsageException("%s: error: %s for help subcommand" % (SCRIPT_NAME, e))
Beispiel #2
0
class Command(object):
    long_descr = None
    short_descr = None
    # XXX: decide how to deal with subcommands options
    opts = [Option('-h', '--help',
                   help="Show this message and exits.",
                   action="store_true")]

    def __init__(self):
        self.parser = None

    def _create_parser(self):
        if self.parser is None:
            self.parser = OptionParser(self.long_descr.splitlines()[1])

    def reset_parser(self):
        self.parser = None
        self._create_parser()

    def setup_options_parser(self, package_options):
        self._create_parser()
        try:
            oo = copy.deepcopy(self.opts)
            for o in oo:
                self.parser.add_option(o)
        except getopt.GetoptError, e:
            raise UsageException("%s: error: %s for help subcommand" % (SCRIPT_NAME, e))
Beispiel #3
0
 def _create_parser(self):
     if self.parser is None:
         self.parser = OptionParser(self.long_descr.splitlines()[1])