Skip to content

Commit

Permalink
Add option to get json directly from a given file
Browse files Browse the repository at this point in the history
  • Loading branch information
chnyda committed Nov 15, 2017
1 parent 067042d commit 1def91d
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions pepper/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ def add_globalopts(self):
Specifying this argument will cause positional arguments to be
ignored.'''))

optgroup.add_option('--json-file', dest='json_file',
help=textwrap.dedent('''\
Specify file containing the JSON to be used by pepper'''))

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

Expand Down Expand Up @@ -322,6 +326,22 @@ def parse_cmd(self):
logger.error("Invalid JSON given.")
raise SystemExit(1)

if self.options.json_file:
try:
with open(self.options.json_file, 'r') as json_content:
try:
return json.load(json_content)
except ValueError:
logger.error("Invalid JSON given.")
raise SystemExit(1)
except Exception as e:
logger.error(
'Cannot open file: {0}, {1}'.format(
self.options.json_file, repr(e)
)
)
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 1def91d

Please sign in to comment.