diff options
author | QMK Bot <hello@qmk.fm> | 2021-02-07 21:03:27 +0000 |
---|---|---|
committer | QMK Bot <hello@qmk.fm> | 2021-02-07 21:03:27 +0000 |
commit | d9dea7c4ec9513f07779094a900702bd0da31c30 (patch) | |
tree | 4bef40ca3409291e2ffc34248d13ac9c22278975 /lib/python/qmk/cli/json2c.py | |
parent | 0e59827023859a428be789a11036d68bd6eda2bd (diff) | |
parent | ccc9c43161282bd6f37813cc85c13da1eb51b88d (diff) |
Merge remote-tracking branch 'origin/master' into develop
Diffstat (limited to 'lib/python/qmk/cli/json2c.py')
-rwxr-xr-x | lib/python/qmk/cli/json2c.py | 18 |
1 files changed, 3 insertions, 15 deletions
diff --git a/lib/python/qmk/cli/json2c.py b/lib/python/qmk/cli/json2c.py index 97d8fb0c33..e7babc0e4c 100755 --- a/lib/python/qmk/cli/json2c.py +++ b/lib/python/qmk/cli/json2c.py @@ -1,7 +1,6 @@ """Generate a keymap.c from a configurator export. """ import json -import sys from milc import cli @@ -11,7 +10,7 @@ import qmk.path @cli.argument('-o', '--output', arg_only=True, type=qmk.path.normpath, help='File to write to') @cli.argument('-q', '--quiet', arg_only=True, action='store_true', help="Quiet mode, only output error messages") -@cli.argument('filename', type=qmk.path.normpath, arg_only=True, help='Configurator JSON file') +@cli.argument('filename', type=qmk.path.FileType('r'), arg_only=True, help='Configurator JSON file') @cli.subcommand('Creates a keymap.c from a QMK Configurator export.') def json2c(cli): """Generate a keymap.c from a configurator export. @@ -20,19 +19,8 @@ def json2c(cli): """ try: - # Parse the configurator from stdin - if cli.args.filename and cli.args.filename.name == '-': - user_keymap = json.load(sys.stdin) - - else: - # Error checking - if not cli.args.filename.exists(): - cli.log.error('JSON file does not exist!') - return False - - # Parse the configurator json file - else: - user_keymap = json.loads(cli.args.filename.read_text()) + # Parse the configurator from json file (or stdin) + user_keymap = json.load(cli.args.filename) except json.decoder.JSONDecodeError as ex: cli.log.error('The JSON input does not appear to be valid.') |