'Given the command-line arguments, figure out which subcommand is being
run, create a parser appropriate to that command, and run it.'

def execute(self):

    try:
        subcommand = self.argv[1]
    except IndexError:
        subcommand = 'help'
    parser = CommandParser(None, usage='%(prog)s    subcommand    [options]    [args]', add_help=False)
    parser.add_argument('--settings')
    parser.add_argument('--pythonpath')
    parser.add_argument('args', nargs='*')
    with suppress(CommandError):
        (options, args) = parser.parse_known_args(self.argv[2:])
        handle_default_options(options)
    try:
        settings.INSTALLED_APPS
    except ImproperlyConfigured as exc:
        self.settings_exception = exc
    if settings.configured:
        if ((subcommand == 'runserver') and ('--noreload' not in self.argv)):
            try:
                autoreload.check_errors(django.setup)()
            except Exception:
                apps.all_models = defaultdict(OrderedDict)
                apps.app_configs = OrderedDict()
                apps.apps_ready = apps.models_ready = apps.ready = True
                _parser = self.fetch_command('runserver').create_parser('django', 'runserver')
                (_options, _args) = _parser.parse_known_args(self.argv[2:])
                for _arg in _args:
                    self.argv.remove(_arg)
        else:
            django.setup()
    self.autocomplete()
    if (subcommand == 'help'):
        if ('--commands' in args):
            sys.stdout.write((self.main_help_text(commands_only=True) + '\n'))
        elif (len(options.args) < 1):
            sys.stdout.write((self.main_help_text() + '\n'))
        else:
            self.fetch_command(options.args[0]).print_help(self.prog_name, options.args[0])
    elif ((subcommand == 'version') or (self.argv[1:] == ['--version'])):
        sys.stdout.write((django.get_version() + '\n'))
    elif (self.argv[1:] in (['--help'], ['-h'])):
        sys.stdout.write((self.main_help_text() + '\n'))
    else:
        self.fetch_command(subcommand).run_from_argv(self.argv)
