Skip to content

Commit 3084763

Browse files
authored
Merge pull request #98 from whiteinge/allow-json
Allow JSON input as the request body
2 parents 2e086d6 + 7bfbeb0 commit 3084763

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

pepper/cli.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff 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'

0 commit comments

Comments
 (0)