Ticket #7972: argvorder.diff

File argvorder.diff, 2.8 KB (added by mukappa, 16 years ago)
  • django/core/management/base.py

     
    7070        parser = self.create_parser(prog_name, subcommand)
    7171        parser.print_help()
    7272
    73     def run_from_argv(self, argv):
    74         parser = self.create_parser(argv[0], argv[1])
    75         options, args = parser.parse_args(argv[2:])
     73    def run_from_argv(self, prog_name, subcommand, argv):
     74        parser = self.create_parser(prog_name, subcommand)
     75        options, args = parser.parse_args(argv)
    7676        handle_default_options(options)
    77         self.execute(*args, **options.__dict__)
     77        prog_args = args[2:]
     78        self.execute(*prog_args, **options.__dict__)
    7879
    7980    def execute(self, *args, **options):
    8081        # Switch to English, because django-admin.py creates database content
  • django/core/management/__init__.py

     
    226226            pass # Ignore any option errors at this point.
    227227
    228228        try:
    229             subcommand = self.argv[1]
     229            subcommand = args[1]
    230230        except IndexError:
    231231            sys.stderr.write("Type '%s help' for usage.\n" % self.prog_name)
    232232            sys.exit(1)
     
    245245        elif self.argv[1:] == ['--help']:
    246246            sys.stderr.write(self.main_help_text() + '\n')
    247247        else:
    248             self.fetch_command(subcommand).run_from_argv(self.argv)
     248            self.fetch_command(subcommand).run_from_argv(args[0], args[1], sys.argv)
    249249
    250250class ProjectManagementUtility(ManagementUtility):
    251251    """
  • tests/regressiontests/admin_scripts/tests.py

     
    910910        self.assertNoOutput(err)
    911911        self.assertOutput(out, "EXECUTE:BaseCommand labels=('testlabel',), options=[('option_a', 'x'), ('option_b', 'y'), ('option_c', '3'), ('pythonpath', None), ('settings', 'alternate_settings'), ('traceback', None)]")
    912912
     913    def test_setting_then_command_then_label_then_options(self):
     914        "Options are correctly handled when they are passed before and after a setting"
     915        args = ['--settings=alternate_settings','base_command','testlabel','--option_a=x','--option_b=y']
     916        out, err = self.run_manage(args)
     917        self.assertNoOutput(err)
     918        self.assertOutput(out, "EXECUTE:BaseCommand labels=('testlabel',), options=[('option_a', 'x'), ('option_b', 'y'), ('option_c', '3'), ('pythonpath', None), ('settings', 'alternate_settings'), ('traceback', None)]")
     919
Back to Top