From 8161e5e92a5e3137b42953ef4b184178879013d1 Mon Sep 17 00:00:00 2001 From: h7x4 Date: Sun, 28 Jul 2024 14:32:13 +0200 Subject: [PATCH] cli: make devscripts subcommand more accessible --- worblehat/main.py | 6 ++++-- worblehat/services/__init__.py | 5 ++++- worblehat/services/argument_parser.py | 17 +++++++++++------ 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/worblehat/main.py b/worblehat/main.py index 041d8f8..9f261e9 100644 --- a/worblehat/main.py +++ b/worblehat/main.py @@ -7,6 +7,7 @@ from sqlalchemy.orm import Session from .services import ( Config, arg_parser, + devscripts_arg_parser, ) from .deadline_daemon import DeadlineDaemon @@ -69,7 +70,7 @@ def main(): from .devscripts.seed_test_data import main main(sql_session) else: - print(f'Error: no such script: {args.script}') + print(devscripts_arg_parser.format_help()) exit(1) exit(0) @@ -83,4 +84,5 @@ def main(): flask_prod_main() exit(0) - print(arg_parser.format_help()) \ No newline at end of file + print(arg_parser.format_help()) + exit(1) \ No newline at end of file diff --git a/worblehat/services/__init__.py b/worblehat/services/__init__.py index 0decc6e..9311630 100644 --- a/worblehat/services/__init__.py +++ b/worblehat/services/__init__.py @@ -1,4 +1,7 @@ -from .argument_parser import arg_parser +from .argument_parser import ( + arg_parser, + devscripts_arg_parser, +) from .bookcase_item import ( create_bookcase_item_from_isbn, is_valid_isbn, diff --git a/worblehat/services/argument_parser.py b/worblehat/services/argument_parser.py index 401257d..fafd168 100644 --- a/worblehat/services/argument_parser.py +++ b/worblehat/services/argument_parser.py @@ -31,12 +31,17 @@ subparsers.add_parser( help = 'Start the web interface in production mode', ) -subparsers.add_parser( - 'devscripts', - help = 'Run development scripts', -).add_argument( - 'script', - help = 'The development script to run', +devscripts_arg_parser = subparsers.add_parser('devscripts', help='Run development scripts') +devscripts_subparsers = devscripts_arg_parser.add_subparsers(dest='script') + +devscripts_subparsers.add_parser( + 'seed-test-data', + help = 'Seed test data in the database', +) + +devscripts_subparsers.add_parser( + 'seed-content-for-deadline-daemon', + help = 'Seed data tailorded for testing the deadline daemon, into the database', ) arg_parser.add_argument(