Skip to content

Commit

Permalink
Merge pull request #98 from whiteinge/allow-json
Browse files Browse the repository at this point in the history
Allow JSON input as the request body
  • Loading branch information
whiteinge authored Dec 29, 2016
2 parents 2e086d6 + 7bfbeb0 commit 3084763
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pepper/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ def add_globalopts(self):
specify the salt-api client to use (local, local_async,
runner, etc)'''))

optgroup.add_option('--json', dest='json_input',
help=textwrap.dedent('''\
Enter JSON at the CLI instead of positional (text) arguments. This
is useful for arguments that need complex data structures.
Specifying this argument will cause positional arguments to be
ignored.'''))

# optgroup.add_option('--out', '--output', dest='output',
# help="Specify the output format for the command output")

Expand Down Expand Up @@ -300,6 +307,14 @@ def parse_cmd(self):
'''
Extract the low data for a command from the passed CLI params
'''
# Short-circuit if JSON was given.
if self.options.json_input:
try:
return json.loads(self.options.json_input)
except ValueError:
logger.error("Invalid JSON given.")
raise SystemExit(1)

args = list(self.args)

client = self.options.client if not self.options.batch else 'local_batch'
Expand Down

0 comments on commit 3084763

Please sign in to comment.