From ede900f56f3fc5dfd1acf02e30fd3056cd1d05f7 Mon Sep 17 00:00:00 2001 From: SimonGreenhill Date: Fri, 12 Aug 2016 17:41:05 +1200 Subject: [PATCH] converting buildwatson command to use argparse --- src/watson/management/commands/buildwatson.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/watson/management/commands/buildwatson.py b/src/watson/management/commands/buildwatson.py index e6e06a4..b2d6c5d 100644 --- a/src/watson/management/commands/buildwatson.py +++ b/src/watson/management/commands/buildwatson.py @@ -58,11 +58,13 @@ class Command(BaseCommand): args = "[[--engine=search_engine] ... ]" help = "Rebuilds the database indices needed by django-watson. You can (re-)build index for selected models by specifying them" - option_list = BaseCommand.option_list + ( - make_option("--engine", - help="Search engine models are registered with"), + def add_arguments(self, parser): + parser.add_argument("apps", nargs="*", action="store", default=[]) + parser.add_argument('--engine', + action="store", + help='Search engine models are registered with' ) - + @transaction.atomic() def handle(self, *args, **options): """Runs the management command.""" @@ -76,12 +78,11 @@ class Command(BaseCommand): else: engine_slug = "default" engine_selected = False - + # get the search engine we'll be checking registered models for, may be "default" search_engine = get_engine(engine_slug) - models = [] - for model_name in args: + for model_name in options['apps']: try: model = apps.get_model(*model_name.split(".")) # app label, model name except TypeError: # were we given only model name without app_name?