diff options
Diffstat (limited to 'lib/python/qmk/cli/format/json.py')
| -rwxr-xr-x | lib/python/qmk/cli/format/json.py | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/lib/python/qmk/cli/format/json.py b/lib/python/qmk/cli/format/json.py index 3670294434..61f5254184 100755 --- a/lib/python/qmk/cli/format/json.py +++ b/lib/python/qmk/cli/format/json.py | |||
| @@ -9,7 +9,7 @@ from milc import cli | |||
| 9 | 9 | ||
| 10 | from qmk.info import info_json | 10 | from qmk.info import info_json |
| 11 | from qmk.json_schema import json_load, validate | 11 | from qmk.json_schema import json_load, validate |
| 12 | from qmk.json_encoders import InfoJSONEncoder, KeymapJSONEncoder, UserspaceJSONEncoder | 12 | from qmk.json_encoders import InfoJSONEncoder, KeymapJSONEncoder, UserspaceJSONEncoder, CommunityModuleJSONEncoder |
| 13 | from qmk.path import normpath | 13 | from qmk.path import normpath |
| 14 | 14 | ||
| 15 | 15 | ||
| @@ -32,6 +32,13 @@ def _detect_json_format(file, json_data): | |||
| 32 | 32 | ||
| 33 | if json_encoder is None: | 33 | if json_encoder is None: |
| 34 | try: | 34 | try: |
| 35 | validate(json_data, 'qmk.community_module.v1') | ||
| 36 | json_encoder = CommunityModuleJSONEncoder | ||
| 37 | except ValidationError: | ||
| 38 | pass | ||
| 39 | |||
| 40 | if json_encoder is None: | ||
| 41 | try: | ||
| 35 | validate(json_data, 'qmk.keyboard.v1') | 42 | validate(json_data, 'qmk.keyboard.v1') |
| 36 | json_encoder = InfoJSONEncoder | 43 | json_encoder = InfoJSONEncoder |
| 37 | except ValidationError as e: | 44 | except ValidationError as e: |
| @@ -54,6 +61,8 @@ def _get_json_encoder(file, json_data): | |||
| 54 | json_encoder = KeymapJSONEncoder | 61 | json_encoder = KeymapJSONEncoder |
| 55 | elif cli.args.format == 'userspace': | 62 | elif cli.args.format == 'userspace': |
| 56 | json_encoder = UserspaceJSONEncoder | 63 | json_encoder = UserspaceJSONEncoder |
| 64 | elif cli.args.format == 'community_module': | ||
| 65 | json_encoder = CommunityModuleJSONEncoder | ||
| 57 | else: | 66 | else: |
| 58 | # This should be impossible | 67 | # This should be impossible |
| 59 | cli.log.error('Unknown format: %s', cli.args.format) | 68 | cli.log.error('Unknown format: %s', cli.args.format) |
| @@ -61,7 +70,7 @@ def _get_json_encoder(file, json_data): | |||
| 61 | 70 | ||
| 62 | 71 | ||
| 63 | @cli.argument('json_file', arg_only=True, type=normpath, help='JSON file to format') | 72 | @cli.argument('json_file', arg_only=True, type=normpath, help='JSON file to format') |
| 64 | @cli.argument('-f', '--format', choices=['auto', 'keyboard', 'keymap', 'userspace'], default='auto', arg_only=True, help='JSON formatter to use (Default: autodetect)') | 73 | @cli.argument('-f', '--format', choices=['auto', 'keyboard', 'keymap', 'userspace', 'community_module'], default='auto', arg_only=True, help='JSON formatter to use (Default: autodetect)') |
| 65 | @cli.argument('-i', '--inplace', action='store_true', arg_only=True, help='If set, will operate in-place on the input file') | 74 | @cli.argument('-i', '--inplace', action='store_true', arg_only=True, help='If set, will operate in-place on the input file') |
| 66 | @cli.argument('-p', '--print', action='store_true', arg_only=True, help='If set, will print the formatted json to stdout ') | 75 | @cli.argument('-p', '--print', action='store_true', arg_only=True, help='If set, will print the formatted json to stdout ') |
| 67 | @cli.subcommand('Generate an info.json file for a keyboard.', hidden=False if cli.config.user.developer else True) | 76 | @cli.subcommand('Generate an info.json file for a keyboard.', hidden=False if cli.config.user.developer else True) |
