11import argparse
2+ import json
23import logging
34from sys import exit
45
1314LOGGER = logging .getLogger (__name__ )
1415
1516
16- def str2bool (v ):
17- if isinstance (v , bool ):
18- return v
19- if v .lower () in ("yes" , "true" , "t" , "y" , "1" ):
20- return True
21- elif v .lower () in ("no" , "false" , "f" , "n" , "0" ):
22- return False
23- else :
24- raise argparse .ArgumentTypeError ("Boolean value expected." )
25-
26-
2717def cli_whoami ():
2818 api = get_mediawiki_api ()
2919 LOGGER .info ("I am %s" , api )
@@ -45,10 +35,8 @@ def cli_check_replica(name: str):
4535 )
4636
4737
48- def cli_task (
49- id : str , run : bool , manual : bool , config : bool , job_name = "cronjob" , param = ""
50- ):
51- task = task_registry .get_task_by_id (id )
38+ def cli_task (task_id : str , run : bool , manual : bool , config : bool , param = "" ):
39+ task = task_registry .get_task_by_id (task_id )
5240 if task is None :
5341 LOGGER .error ("Task not found" )
5442 exit (1 )
@@ -57,7 +45,7 @@ def cli_task(
5745
5846 if config :
5947 LOGGER .info ("Task configuration for task %s" , task .id )
60- LOGGER .info (task .get_task_configuration ())
48+ LOGGER .info (json . dumps ( task .get_task_configuration () ))
6149 exit (0 )
6250
6351 if run :
@@ -88,47 +76,31 @@ def main():
8876 )
8977
9078 task_parser = subparsers .add_parser ("task" )
91- task_parser .add_argument ("id " , help = "Task ID" )
79+ task_parser .add_argument ("task_id " , help = "Task ID" )
9280 task_parser .add_argument (
9381 "--run" ,
9482 dest = "run" ,
95- type = str2bool ,
96- nargs = "?" ,
97- const = True ,
83+ action = "store_true" ,
9884 default = False ,
9985 help = "Run the task" ,
10086 )
10187 task_parser .add_argument (
10288 "--manual" ,
10389 dest = "manual" ,
104- type = str2bool ,
105- nargs = "?" ,
106- const = True ,
90+ action = "store_true" ,
10791 default = False ,
10892 help = "Manually runs the task" ,
10993 )
11094 task_parser .add_argument (
11195 "--config" ,
11296 dest = "config" ,
113- type = str2bool ,
114- nargs = "?" ,
115- const = True ,
97+ action = "store_true" ,
11698 default = False ,
11799 help = "Shows the task configuration" ,
118100 )
119- task_parser .add_argument (
120- "--job-name" ,
121- dest = "job_name" ,
122- type = str ,
123- nargs = "?" ,
124- default = "cronjob" ,
125- help = "Job name to record to database" ,
126- )
127101 task_parser .add_argument (
128102 "--param" ,
129103 dest = "param" ,
130- type = str ,
131- nargs = "?" ,
132104 default = "" ,
133105 help = "Additional param passed to the job" ,
134106 )
0 commit comments