File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -94,6 +94,13 @@ def add_globalopts(self):
9494 specify the salt-api client to use (local, local_async,
9595 runner, etc)''' ))
9696
97+ optgroup .add_option ('--json' , dest = 'json_input' ,
98+ help = textwrap .dedent ('''\
99+ Enter JSON at the CLI instead of positional (text) arguments. This
100+ is useful for arguments that need complex data structures.
101+ Specifying this argument will cause positional arguments to be
102+ ignored.''' ))
103+
97104 # optgroup.add_option('--out', '--output', dest='output',
98105 # help="Specify the output format for the command output")
99106
@@ -300,6 +307,14 @@ def parse_cmd(self):
300307 '''
301308 Extract the low data for a command from the passed CLI params
302309 '''
310+ # Short-circuit if JSON was given.
311+ if self .options .json_input :
312+ try :
313+ return json .loads (self .options .json_input )
314+ except ValueError :
315+ logger .error ("Invalid JSON given." )
316+ raise SystemExit (1 )
317+
303318 args = list (self .args )
304319
305320 client = self .options .client if not self .options .batch else 'local_batch'
You can’t perform that action at this time.
0 commit comments