Ejemplo n.º 1
0
    def run(self, args):
        """
        Handle program arguments, set up the application and call
        a subcommand or enter interactive mode. Return exit code.

        :param args: (``list``) Arguments without the binary name.
        """
        if not isinstance(args, (tuple, list)):
            raise TypeError("args must be a list")
        try:
            options = docopt.docopt(self.get_usage(), args,
                    version=util.get_version(), help=False, options_first=True)
        except docopt.DocoptLanguageError as exc:
            self.app.stderr.write("%s\n" % str(exc))
            return 1
        if options.pop('--help', False):
            self.app.stdout.write(self.get_usage())
            self.app.stdout.write("\nCommands:\n")
            self.app.stdout.write("    %s\n" % " ".join(
                n for n in sorted(self.app.command_manager)))
            return 0
        if options.pop('--version', False):
            self.app.print_version()
            return 0
        self.app.setup(options)
        if options['<command>'] is None:
            return self.start_interactive_mode()
        else:
            LOG().debug('running command "%s"', options['<command>'])
            return self.run_subcommand(
                    options['<command>'], options['<args>'])
Ejemplo n.º 2
0
    def run(self, args):
        """
        Handle program arguments, set up the application and call
        a subcommand or enter interactive mode. Return exit code.

        :param args: (``list``) Arguments without the binary name.
        """
        if not isinstance(args, (tuple, list)):
            raise TypeError("args must be a list")
        try:
            options = docopt.docopt(self.get_usage(),
                                    args,
                                    version=util.get_version(),
                                    help=False,
                                    options_first=True)
        except docopt.DocoptLanguageError as exc:
            self.app.stderr.write("%s\n" % str(exc))
            return 1
        if options.pop('--help', False):
            self.app.stdout.write(self.get_usage())
            self.app.stdout.write("\nCommands:\n")
            self.app.stdout.write(
                "    %s\n" %
                " ".join(n for n in sorted(self.app.command_manager)))
            return 0
        if options.pop('--version', False):
            self.app.print_version()
            return 0
        self.app.setup(options)
        if options['<command>'] is None:
            return self.start_interactive_mode()
        else:
            LOG().debug('running command "%s"', options['<command>'])
            return self.run_subcommand(options['<command>'], options['<args>'])
Ejemplo n.º 3
0
 def print_version(self):
     """ Print version of this egg to stdout. """
     self.stdout.write("%s\n" % util.get_version())