From f17b24e407385eb18651bf023a187347aa9c1f75 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Fri, 6 Jun 2014 22:39:33 +0200 Subject: Converted remaining management commands to argparse --- .../admin_scripts/management/commands/base_command.py | 14 ++++++-------- .../management/commands/custom_startproject.py | 11 ++++------- .../management/commands/label_command.py | 1 - tests/admin_scripts/tests.py | 19 +++++++++---------- 4 files changed, 19 insertions(+), 26 deletions(-) (limited to 'tests/admin_scripts') diff --git a/tests/admin_scripts/management/commands/base_command.py b/tests/admin_scripts/management/commands/base_command.py index c313235ead..14e9152d9d 100644 --- a/tests/admin_scripts/management/commands/base_command.py +++ b/tests/admin_scripts/management/commands/base_command.py @@ -1,17 +1,15 @@ -from optparse import make_option - from django.core.management.base import BaseCommand class Command(BaseCommand): - option_list = BaseCommand.option_list + ( - make_option('--option_a', '-a', action='store', dest='option_a', default='1'), - make_option('--option_b', '-b', action='store', dest='option_b', default='2'), - make_option('--option_c', '-c', action='store', dest='option_c', default='3'), - ) help = 'Test basic commands' requires_system_checks = False - args = '[labels ...]' + + def add_arguments(self, parser): + parser.add_argument('args', nargs='*') + parser.add_argument('--option_a', '-a', default='1') + parser.add_argument('--option_b', '-b', default='2') + parser.add_argument('--option_c', '-c', default='3') def handle(self, *labels, **options): print('EXECUTE:BaseCommand labels=%s, options=%s' % (labels, sorted(options.items()))) diff --git a/tests/admin_scripts/management/commands/custom_startproject.py b/tests/admin_scripts/management/commands/custom_startproject.py index 8144b5b69c..0d9c7d339e 100644 --- a/tests/admin_scripts/management/commands/custom_startproject.py +++ b/tests/admin_scripts/management/commands/custom_startproject.py @@ -1,11 +1,8 @@ -from optparse import make_option - from django.core.management.commands.startproject import Command as BaseCommand class Command(BaseCommand): - option_list = BaseCommand.option_list + ( - make_option('--extra', - action='store', dest='extra', - help='An arbitrary extra value passed to the context'), - ) + def add_arguments(self, parser): + super(Command, self).add_arguments(parser) + parser.add_argument('--extra', + help='An arbitrary extra value passed to the context') diff --git a/tests/admin_scripts/management/commands/label_command.py b/tests/admin_scripts/management/commands/label_command.py index 9bba413ff3..5bffeb3ae2 100644 --- a/tests/admin_scripts/management/commands/label_command.py +++ b/tests/admin_scripts/management/commands/label_command.py @@ -4,7 +4,6 @@ from django.core.management.base import LabelCommand class Command(LabelCommand): help = "Test Label-based commands" requires_system_checks = False - args = '