Example #1
0
File: base.py Project: strogo/gig
    def get_version(self):
        """
        Return the Gig version, which should be correct for all built-in
        commands. User-supplied commands should override this method.

        """
        return gig.get_version()
Example #2
0
File: loader.py Project: strogo/gig
    def execute(self):
        """
        Given the command-line arguments, this figures out which subcommand is
        being run, creates a parser appropriate to that command, and runs it.
        """
        # Preprocess options to extract --pythonpath.  These options could
        # affect the commands that are available, so they must be processed
        # early.
        parser = LaxOptionParser(usage="%prog subcommand [options] [args]",
                                 version=gig.get_version(),
                                 option_list=BaseCommand.option_list)
                                 
        options, args = parser.parse_args(self.argv)
        handle_default_options(options)
         
        try:
            options, args = parser.parse_args(self.argv)
            handle_default_options(options)
        except:
            print "EXCEPTION DAMMIT"
            pass # Ignore any option errors at this point.

        try:
            subcommand = self.argv[1]
        except IndexError:
            sys.stderr.write("Type '%s help' for usage.\n" % self.prog_name)
            sys.exit(1)

        if subcommand == 'help':
            if len(args) > 2:
                self.fetch_command(args[2]).print_help(self.prog_name, args[2])
            else:
                parser.print_lax_help()
                sys.stderr.write(self.main_help_text() + '\n')
                sys.exit(1)

        # Special-cases: We want 'gig --version' and 'gig --help' to work, for
        # backwards compatibility.
        elif self.argv[1:] == ['--version']:
            # LaxOptionParser already takes care of printing the version.
            pass
        elif self.argv[1:] == ['--help']:
            parser.print_lax_help()
            sys.stderr.write(self.main_help_text() + '\n')
        else:
            self.fetch_command(subcommand).run_from_argv(self.argv)