diff options
author | Zach White <skullydazed@users.noreply.github.com> | 2020-05-27 00:43:22 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-27 09:43:22 +0200 |
commit | 1a5dc278bc5aadfce220e18d53ff612d6592a12b (patch) | |
tree | 3de4eefff5cf91f6e11728d412618169b047d118 /lib/python | |
parent | 10c1e1b3abd5c91dd498610c985a9f4873a20288 (diff) | |
download | qmk_firmware-1a5dc278bc5aadfce220e18d53ff612d6592a12b.tar.gz qmk_firmware-1a5dc278bc5aadfce220e18d53ff612d6592a12b.zip |
Fix running qmk info without any arguments (#9218)
Diffstat (limited to 'lib/python')
-rwxr-xr-x | lib/python/qmk/cli/info.py | 93 | ||||
-rw-r--r-- | lib/python/qmk/path.py | 7 |
2 files changed, 59 insertions, 41 deletions
diff --git a/lib/python/qmk/cli/info.py b/lib/python/qmk/cli/info.py index 6977673e2..5e4b39141 100755 --- a/lib/python/qmk/cli/info.py +++ b/lib/python/qmk/cli/info.py | |||
@@ -72,6 +72,53 @@ def show_matrix(info_json, title_caps=True): | |||
72 | print(render_layout(info_json['layouts'][layout_name]['layout'], labels)) | 72 | print(render_layout(info_json['layouts'][layout_name]['layout'], labels)) |
73 | 73 | ||
74 | 74 | ||
75 | def print_friendly_output(info_json): | ||
76 | """Print the info.json in a friendly text format. | ||
77 | """ | ||
78 | cli.echo('{fg_blue}Keyboard Name{fg_reset}: %s', info_json.get('keyboard_name', 'Unknown')) | ||
79 | cli.echo('{fg_blue}Manufacturer{fg_reset}: %s', info_json.get('manufacturer', 'Unknown')) | ||
80 | if 'url' in info_json: | ||
81 | cli.echo('{fg_blue}Website{fg_reset}: %s', info_json.get('url', '')) | ||
82 | if info_json.get('maintainer', 'qmk') == 'qmk': | ||
83 | cli.echo('{fg_blue}Maintainer{fg_reset}: QMK Community') | ||
84 | else: | ||
85 | cli.echo('{fg_blue}Maintainer{fg_reset}: %s', info_json['maintainer']) | ||
86 | cli.echo('{fg_blue}Keyboard Folder{fg_reset}: %s', info_json.get('keyboard_folder', 'Unknown')) | ||
87 | cli.echo('{fg_blue}Layouts{fg_reset}: %s', ', '.join(sorted(info_json['layouts'].keys()))) | ||
88 | if 'width' in info_json and 'height' in info_json: | ||
89 | cli.echo('{fg_blue}Size{fg_reset}: %s x %s' % (info_json['width'], info_json['height'])) | ||
90 | cli.echo('{fg_blue}Processor{fg_reset}: %s', info_json.get('processor', 'Unknown')) | ||
91 | cli.echo('{fg_blue}Bootloader{fg_reset}: %s', info_json.get('bootloader', 'Unknown')) | ||
92 | |||
93 | if cli.config.info.layouts: | ||
94 | show_layouts(info_json, True) | ||
95 | |||
96 | if cli.config.info.matrix: | ||
97 | show_matrix(info_json, True) | ||
98 | |||
99 | if cli.config_source.info.keymap and cli.config_source.info.keymap != 'config_file': | ||
100 | show_keymap(info_json, True) | ||
101 | |||
102 | |||
103 | def print_text_output(info_json): | ||
104 | """Print the info.json in a plain text format. | ||
105 | """ | ||
106 | for key in sorted(info_json): | ||
107 | if key == 'layouts': | ||
108 | cli.echo('{fg_blue}layouts{fg_reset}: %s', ', '.join(sorted(info_json['layouts'].keys()))) | ||
109 | else: | ||
110 | cli.echo('{fg_blue}%s{fg_reset}: %s', key, info_json[key]) | ||
111 | |||
112 | if cli.config.info.layouts: | ||
113 | show_layouts(info_json, False) | ||
114 | |||
115 | if cli.config.info.matrix: | ||
116 | show_matrix(info_json, False) | ||
117 | |||
118 | if cli.config_source.info.keymap and cli.config_source.info.keymap != 'config_file': | ||
119 | show_keymap(info_json, False) | ||
120 | |||
121 | |||
75 | @cli.argument('-kb', '--keyboard', help='Keyboard to show info for.') | 122 | @cli.argument('-kb', '--keyboard', help='Keyboard to show info for.') |
76 | @cli.argument('-km', '--keymap', help='Show the layers for a JSON keymap too.') | 123 | @cli.argument('-km', '--keymap', help='Show the layers for a JSON keymap too.') |
77 | @cli.argument('-l', '--layouts', action='store_true', help='Render the layouts.') | 124 | @cli.argument('-l', '--layouts', action='store_true', help='Render the layouts.') |
@@ -84,8 +131,13 @@ def info(cli): | |||
84 | """Compile an info.json for a particular keyboard and pretty-print it. | 131 | """Compile an info.json for a particular keyboard and pretty-print it. |
85 | """ | 132 | """ |
86 | # Determine our keyboard(s) | 133 | # Determine our keyboard(s) |
134 | if not cli.config.info.keyboard: | ||
135 | cli.log.error('Missing paramater: --keyboard') | ||
136 | cli.subcommands['info'].print_help() | ||
137 | exit(1) | ||
138 | |||
87 | if not is_keyboard(cli.config.info.keyboard): | 139 | if not is_keyboard(cli.config.info.keyboard): |
88 | cli.log.error('Invalid keyboard: %s!', cli.config.info.keyboard) | 140 | cli.log.error('Invalid keyboard: "%s"', cli.config.info.keyboard) |
89 | exit(1) | 141 | exit(1) |
90 | 142 | ||
91 | # Build the info.json file | 143 | # Build the info.json file |
@@ -97,45 +149,10 @@ def info(cli): | |||
97 | exit() | 149 | exit() |
98 | 150 | ||
99 | if cli.args.format == 'text': | 151 | if cli.args.format == 'text': |
100 | for key in sorted(kb_info_json): | 152 | print_text_output(kb_info_json) |
101 | if key == 'layouts': | ||
102 | cli.echo('{fg_blue}layouts{fg_reset}: %s', ', '.join(sorted(kb_info_json['layouts'].keys()))) | ||
103 | else: | ||
104 | cli.echo('{fg_blue}%s{fg_reset}: %s', key, kb_info_json[key]) | ||
105 | |||
106 | if cli.config.info.layouts: | ||
107 | show_layouts(kb_info_json, False) | ||
108 | |||
109 | if cli.config.info.matrix: | ||
110 | show_matrix(kb_info_json, False) | ||
111 | |||
112 | if cli.config_source.info.keymap and cli.config_source.info.keymap != 'config_file': | ||
113 | show_keymap(kb_info_json, False) | ||
114 | 153 | ||
115 | elif cli.args.format == 'friendly': | 154 | elif cli.args.format == 'friendly': |
116 | cli.echo('{fg_blue}Keyboard Name{fg_reset}: %s', kb_info_json.get('keyboard_name', 'Unknown')) | 155 | print_friendly_output(kb_info_json) |
117 | cli.echo('{fg_blue}Manufacturer{fg_reset}: %s', kb_info_json.get('manufacturer', 'Unknown')) | ||
118 | if 'url' in kb_info_json: | ||
119 | cli.echo('{fg_blue}Website{fg_reset}: %s', kb_info_json['url']) | ||
120 | if kb_info_json.get('maintainer') == 'qmk': | ||
121 | cli.echo('{fg_blue}Maintainer{fg_reset}: QMK Community') | ||
122 | else: | ||
123 | cli.echo('{fg_blue}Maintainer{fg_reset}: %s', kb_info_json.get('maintainer', 'qmk')) | ||
124 | cli.echo('{fg_blue}Keyboard Folder{fg_reset}: %s', kb_info_json.get('keyboard_folder', 'Unknown')) | ||
125 | cli.echo('{fg_blue}Layouts{fg_reset}: %s', ', '.join(sorted(kb_info_json['layouts'].keys()))) | ||
126 | if 'width' in kb_info_json and 'height' in kb_info_json: | ||
127 | cli.echo('{fg_blue}Size{fg_reset}: %s x %s' % (kb_info_json['width'], kb_info_json['height'])) | ||
128 | cli.echo('{fg_blue}Processor{fg_reset}: %s', kb_info_json.get('processor', 'Unknown')) | ||
129 | cli.echo('{fg_blue}Bootloader{fg_reset}: %s', kb_info_json.get('bootloader', 'Unknown')) | ||
130 | |||
131 | if cli.config.info.layouts: | ||
132 | show_layouts(kb_info_json, True) | ||
133 | |||
134 | if cli.config.info.matrix: | ||
135 | show_matrix(kb_info_json, True) | ||
136 | |||
137 | if cli.config_source.info.keymap and cli.config_source.info.keymap != 'config_file': | ||
138 | show_keymap(kb_info_json, True) | ||
139 | 156 | ||
140 | else: | 157 | else: |
141 | cli.log.error('Unknown format: %s', cli.args.format) | 158 | cli.log.error('Unknown format: %s', cli.args.format) |
diff --git a/lib/python/qmk/path.py b/lib/python/qmk/path.py index 8df6f0e91..591fad034 100644 --- a/lib/python/qmk/path.py +++ b/lib/python/qmk/path.py | |||
@@ -11,9 +11,10 @@ from qmk.errors import NoSuchKeyboardError | |||
11 | def is_keyboard(keyboard_name): | 11 | def is_keyboard(keyboard_name): |
12 | """Returns True if `keyboard_name` is a keyboard we can compile. | 12 | """Returns True if `keyboard_name` is a keyboard we can compile. |
13 | """ | 13 | """ |
14 | keyboard_path = QMK_FIRMWARE / 'keyboards' / keyboard_name | 14 | if keyboard_name: |
15 | rules_mk = keyboard_path / 'rules.mk' | 15 | keyboard_path = QMK_FIRMWARE / 'keyboards' / keyboard_name |
16 | return rules_mk.exists() | 16 | rules_mk = keyboard_path / 'rules.mk' |
17 | return rules_mk.exists() | ||
17 | 18 | ||
18 | 19 | ||
19 | def under_qmk_firmware(): | 20 | def under_qmk_firmware(): |