Skip to content

Commit

Permalink
Merge pull request #113 from chnyda/develop
Browse files Browse the repository at this point in the history
Add option to get json directly from a given file
  • Loading branch information
gtmanfred authored Nov 27, 2017
2 parents 067042d + 1def91d commit 4144935
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 4144935

Please sign in to comment.