@@ -61,7 +61,7 @@ def create_cli(api_client, json_file, json, version):
6161
6262
6363@click .command (context_settings = CONTEXT_SETTINGS )
64- @click .option ('--job-id' , required = True , type = JobIdClickType (), help = JobIdClickType .help )
64+ @click .option ('--job-id' , default = None , type = JobIdClickType (), help = JobIdClickType .help )
6565@click .option ('--json-file' , default = None , type = click .Path (),
6666 help = 'File containing partial JSON request to POST to /api/2.*/jobs/reset. '
6767 'For more, read full help message.' )
@@ -87,10 +87,25 @@ def reset_cli(api_client, json_file, json, job_id, version):
8787 with open (json_file , 'r' ) as f :
8888 json = f .read ()
8989 deser_json = json_loads (json )
90+ # If the payload is defined using the API definition rather than the CLI
91+ # extract the settings data.
92+ new_settings = deser_json ['new_settings' ] if (
93+ 'new_settings' in deser_json ) else deser_json
94+
95+ # If job id is not defined in the call we fall back to checking
96+ # the JSON for a job_id property
97+ if job_id is None :
98+ if 'job_id' in deser_json :
99+ job_id = deser_json ['job_id' ]
100+ else :
101+ raise RuntimeError (
102+ 'Either --job-id or a root-level json key "job_id" should be provided' )
103+
90104 request_body = {
91105 'job_id' : job_id ,
92- 'new_settings' : deser_json
106+ 'new_settings' : new_settings
93107 }
108+
94109 JobsApi (api_client ).reset_job (request_body , version = version )
95110
96111
0 commit comments