From 1def91dfb1fa41fb1edb4e264dbc3efbd50d83b3 Mon Sep 17 00:00:00 2001 From: chnyda Date: Wed, 15 Nov 2017 12:22:54 +0100 Subject: [PATCH] Add option to get json directly from a given file --- pepper/cli.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/pepper/cli.py b/pepper/cli.py index 82eea31..b1670fb 100644 --- a/pepper/cli.py +++ b/pepper/cli.py @@ -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") @@ -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'