def execute(self):
<EOL>parser = NewOptionParser(prog=self.prog_name,<EOL>usage=self.usage_info,<EOL>version=self.get_version(),<EOL>formatter = NewFormatter(),<EOL>add_help_option = False,<EOL>option_list=self.option_list)<EOL>if not self.global_options:<EOL><INDENT>global_options, args = parser.parse_args(self.argv)<EOL>handle_default_options(global_options)<EOL>args = args[<NUM_LIT:1>:]<EOL><DEDENT>else:<EOL><INDENT>global_options = self.global_options<EOL>args = self.argv<EOL><DEDENT>def print_help(global_options):<EOL><INDENT>parser.print_help()<EOL>sys.stderr.write(self.print_help_info(global_options) + '<STR_LIT:\n>')<EOL>sys.exit(<NUM_LIT:0>)<EOL><DEDENT>if len(args) == <NUM_LIT:0>:<EOL><INDENT>if global_options.version:<EOL><INDENT>print(self.get_version())<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>else:<EOL><INDENT>print_help(global_options)<EOL>sys.ext(<NUM_LIT:1>)<EOL><DEDENT><DEDENT>try:<EOL><INDENT>subcommand = args[<NUM_LIT:0>]<EOL><DEDENT>except IndexError:<EOL><INDENT>subcommand = '<STR_LIT>' <EOL><DEDENT>if subcommand == '<STR_LIT>':<EOL><INDENT>if len(args) > <NUM_LIT:1>:<EOL><INDENT>command = self.fetch_command(global_options, args[<NUM_LIT:1>])<EOL>if issubclass(command, CommandManager):<EOL><INDENT>cmd = command(['<STR_LIT>'], None, '<STR_LIT>' % (self.prog_name, args[<NUM_LIT:1>]), global_options=global_options)<EOL>cmd.execute()<EOL><DEDENT>else:<EOL><INDENT>command().print_help(self.prog_name, args[<NUM_LIT:1>])<EOL><DEDENT>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>else:<EOL><INDENT>print_help(global_options)<EOL><DEDENT><DEDENT>if global_options.help:<EOL><INDENT>print_help(global_options)<EOL><DEDENT>else:<EOL><INDENT>command = self.fetch_command(global_options, subcommand)<EOL>if issubclass(command, CommandManager):<EOL><INDENT>cmd = command(args[<NUM_LIT:1>:], None, '<STR_LIT>' % (self.prog_name, subcommand), global_options=global_options)<EOL>cmd.execute()<EOL><DEDENT>else:<EOL><INDENT>cmd = command()<EOL>cmd.run_from_argv(self.prog_name, subcommand, global_options, args[<NUM_LIT:1>:])<EOL><DEDENT><DEDENT>
Given the command-line arguments, this figures out which subcommand is
being run, creates a parser appropriate to that command, and runs it.