diff options
author | Ryan <fauxpark@gmail.com> | 2020-10-07 10:46:10 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-06 16:46:10 -0700 |
commit | 2c9ffd47391b8dec98db94bef9b2f5c14a57cf94 (patch) | |
tree | 57f743159e972e3e2cd215ab256675d3c84d1832 /lib | |
parent | 2013f6313430b977e557e482d30daa279a46e75d (diff) | |
download | qmk_firmware-2c9ffd47391b8dec98db94bef9b2f5c14a57cf94.tar.gz qmk_firmware-2c9ffd47391b8dec98db94bef9b2f5c14a57cf94.zip |
CLI: update subcommands to use return instead of exit() (#10323)
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/python/qmk/cli/doctor.py | 2 | ||||
-rwxr-xr-x | lib/python/qmk/cli/info.py | 11 | ||||
-rwxr-xr-x | lib/python/qmk/cli/json/keymap.py | 2 | ||||
-rwxr-xr-x | lib/python/qmk/cli/json2c.py | 4 | ||||
-rwxr-xr-x | lib/python/qmk/cli/kle2json.py | 6 | ||||
-rw-r--r-- | lib/python/qmk/cli/list/keymaps.py | 2 | ||||
-rwxr-xr-x | lib/python/qmk/cli/new/keymap.py | 6 | ||||
-rw-r--r-- | lib/python/qmk/tests/.gitignore | 2 | ||||
-rw-r--r-- | lib/python/qmk/tests/test_cli_commands.py | 3 |
9 files changed, 20 insertions, 18 deletions
diff --git a/lib/python/qmk/cli/doctor.py b/lib/python/qmk/cli/doctor.py index bad864f72..984c308d1 100755 --- a/lib/python/qmk/cli/doctor.py +++ b/lib/python/qmk/cli/doctor.py | |||
@@ -364,3 +364,5 @@ def doctor(cli): | |||
364 | else: | 364 | else: |
365 | cli.log.info('{fg_yellow}Problems detected, please fix these problems before proceeding.') | 365 | cli.log.info('{fg_yellow}Problems detected, please fix these problems before proceeding.') |
366 | # FIXME(skullydazed/unclaimed): Link to a document about troubleshooting, or discord or something | 366 | # FIXME(skullydazed/unclaimed): Link to a document about troubleshooting, or discord or something |
367 | |||
368 | return ok | ||
diff --git a/lib/python/qmk/cli/info.py b/lib/python/qmk/cli/info.py index 5e4b39141..0e64d4074 100755 --- a/lib/python/qmk/cli/info.py +++ b/lib/python/qmk/cli/info.py | |||
@@ -134,11 +134,11 @@ def info(cli): | |||
134 | if not cli.config.info.keyboard: | 134 | if not cli.config.info.keyboard: |
135 | cli.log.error('Missing paramater: --keyboard') | 135 | cli.log.error('Missing paramater: --keyboard') |
136 | cli.subcommands['info'].print_help() | 136 | cli.subcommands['info'].print_help() |
137 | exit(1) | 137 | return False |
138 | 138 | ||
139 | if not is_keyboard(cli.config.info.keyboard): | 139 | if not is_keyboard(cli.config.info.keyboard): |
140 | cli.log.error('Invalid keyboard: "%s"', cli.config.info.keyboard) | 140 | cli.log.error('Invalid keyboard: "%s"', cli.config.info.keyboard) |
141 | exit(1) | 141 | return False |
142 | 142 | ||
143 | # Build the info.json file | 143 | # Build the info.json file |
144 | kb_info_json = info_json(cli.config.info.keyboard) | 144 | kb_info_json = info_json(cli.config.info.keyboard) |
@@ -146,13 +146,10 @@ def info(cli): | |||
146 | # Output in the requested format | 146 | # Output in the requested format |
147 | if cli.args.format == 'json': | 147 | if cli.args.format == 'json': |
148 | print(json.dumps(kb_info_json)) | 148 | print(json.dumps(kb_info_json)) |
149 | exit() | 149 | elif cli.args.format == 'text': |
150 | |||
151 | if cli.args.format == 'text': | ||
152 | print_text_output(kb_info_json) | 150 | print_text_output(kb_info_json) |
153 | |||
154 | elif cli.args.format == 'friendly': | 151 | elif cli.args.format == 'friendly': |
155 | print_friendly_output(kb_info_json) | 152 | print_friendly_output(kb_info_json) |
156 | |||
157 | else: | 153 | else: |
158 | cli.log.error('Unknown format: %s', cli.args.format) | 154 | cli.log.error('Unknown format: %s', cli.args.format) |
155 | return False | ||
diff --git a/lib/python/qmk/cli/json/keymap.py b/lib/python/qmk/cli/json/keymap.py index c97a2d046..2af9faaa7 100755 --- a/lib/python/qmk/cli/json/keymap.py +++ b/lib/python/qmk/cli/json/keymap.py | |||
@@ -13,4 +13,4 @@ def json_keymap(cli): | |||
13 | """Renamed to `qmk json2c`. | 13 | """Renamed to `qmk json2c`. |
14 | """ | 14 | """ |
15 | cli.log.error('This command has been renamed to `qmk json2c`.') | 15 | cli.log.error('This command has been renamed to `qmk json2c`.') |
16 | exit(1) | 16 | return False |
diff --git a/lib/python/qmk/cli/json2c.py b/lib/python/qmk/cli/json2c.py index af0d80a9a..2a9009436 100755 --- a/lib/python/qmk/cli/json2c.py +++ b/lib/python/qmk/cli/json2c.py | |||
@@ -22,12 +22,12 @@ def json2c(cli): | |||
22 | # TODO(skullydazed/anyone): Read file contents from STDIN | 22 | # TODO(skullydazed/anyone): Read file contents from STDIN |
23 | cli.log.error('Reading from STDIN is not (yet) supported.') | 23 | cli.log.error('Reading from STDIN is not (yet) supported.') |
24 | cli.print_usage() | 24 | cli.print_usage() |
25 | exit(1) | 25 | return False |
26 | 26 | ||
27 | if not cli.args.filename.exists(): | 27 | if not cli.args.filename.exists(): |
28 | cli.log.error('JSON file does not exist!') | 28 | cli.log.error('JSON file does not exist!') |
29 | cli.print_usage() | 29 | cli.print_usage() |
30 | exit(1) | 30 | return False |
31 | 31 | ||
32 | # Environment processing | 32 | # Environment processing |
33 | if cli.args.output and cli.args.output.name == '-': | 33 | if cli.args.output and cli.args.output.name == '-': |
diff --git a/lib/python/qmk/cli/kle2json.py b/lib/python/qmk/cli/kle2json.py index 798f95fd1..3d1bb8c43 100755 --- a/lib/python/qmk/cli/kle2json.py +++ b/lib/python/qmk/cli/kle2json.py | |||
@@ -37,7 +37,8 @@ def kle2json(cli): | |||
37 | file_path = Path(os.environ['ORIG_CWD'], cli.args.filename) | 37 | file_path = Path(os.environ['ORIG_CWD'], cli.args.filename) |
38 | # Check for valid file_path for more graceful failure | 38 | # Check for valid file_path for more graceful failure |
39 | if not file_path.exists(): | 39 | if not file_path.exists(): |
40 | return cli.log.error('File {fg_cyan}%s{style_reset_all} was not found.', file_path) | 40 | cli.log.error('File {fg_cyan}%s{style_reset_all} was not found.', file_path) |
41 | return False | ||
41 | out_path = file_path.parent | 42 | out_path = file_path.parent |
42 | raw_code = file_path.open().read() | 43 | raw_code = file_path.open().read() |
43 | # Check if info.json exists, allow overwrite with force | 44 | # Check if info.json exists, allow overwrite with force |
@@ -50,8 +51,7 @@ def kle2json(cli): | |||
50 | except Exception as e: | 51 | except Exception as e: |
51 | cli.log.error('Could not parse KLE raw data: %s', raw_code) | 52 | cli.log.error('Could not parse KLE raw data: %s', raw_code) |
52 | cli.log.exception(e) | 53 | cli.log.exception(e) |
53 | # FIXME: This should be better | 54 | return False |
54 | return cli.log.error('Could not parse KLE raw data.') | ||
55 | keyboard = OrderedDict( | 55 | keyboard = OrderedDict( |
56 | keyboard_name=kle.name, | 56 | keyboard_name=kle.name, |
57 | url='', | 57 | url='', |
diff --git a/lib/python/qmk/cli/list/keymaps.py b/lib/python/qmk/cli/list/keymaps.py index b18289eb3..49bc84b2c 100644 --- a/lib/python/qmk/cli/list/keymaps.py +++ b/lib/python/qmk/cli/list/keymaps.py | |||
@@ -15,7 +15,7 @@ def list_keymaps(cli): | |||
15 | """ | 15 | """ |
16 | if not is_keyboard(cli.config.list_keymaps.keyboard): | 16 | if not is_keyboard(cli.config.list_keymaps.keyboard): |
17 | cli.log.error('Keyboard %s does not exist!', cli.config.list_keymaps.keyboard) | 17 | cli.log.error('Keyboard %s does not exist!', cli.config.list_keymaps.keyboard) |
18 | exit(1) | 18 | return False |
19 | 19 | ||
20 | for name in qmk.keymap.list_keymaps(cli.config.list_keymaps.keyboard): | 20 | for name in qmk.keymap.list_keymaps(cli.config.list_keymaps.keyboard): |
21 | print(name) | 21 | print(name) |
diff --git a/lib/python/qmk/cli/new/keymap.py b/lib/python/qmk/cli/new/keymap.py index 474fe7974..52c564997 100755 --- a/lib/python/qmk/cli/new/keymap.py +++ b/lib/python/qmk/cli/new/keymap.py | |||
@@ -29,15 +29,15 @@ def new_keymap(cli): | |||
29 | # check directories | 29 | # check directories |
30 | if not kb_path.exists(): | 30 | if not kb_path.exists(): |
31 | cli.log.error('Keyboard %s does not exist!', kb_path) | 31 | cli.log.error('Keyboard %s does not exist!', kb_path) |
32 | exit(1) | 32 | return False |
33 | 33 | ||
34 | if not keymap_path_default.exists(): | 34 | if not keymap_path_default.exists(): |
35 | cli.log.error('Keyboard default %s does not exist!', keymap_path_default) | 35 | cli.log.error('Keyboard default %s does not exist!', keymap_path_default) |
36 | exit(1) | 36 | return False |
37 | 37 | ||
38 | if keymap_path_new.exists(): | 38 | if keymap_path_new.exists(): |
39 | cli.log.error('Keymap %s already exists!', keymap_path_new) | 39 | cli.log.error('Keymap %s already exists!', keymap_path_new) |
40 | exit(1) | 40 | return False |
41 | 41 | ||
42 | # create user directory with default keymap files | 42 | # create user directory with default keymap files |
43 | shutil.copytree(keymap_path_default, keymap_path_new, symlinks=True) | 43 | shutil.copytree(keymap_path_default, keymap_path_new, symlinks=True) |
diff --git a/lib/python/qmk/tests/.gitignore b/lib/python/qmk/tests/.gitignore new file mode 100644 index 000000000..eeb6581b8 --- /dev/null +++ b/lib/python/qmk/tests/.gitignore | |||
@@ -0,0 +1,2 @@ | |||
1 | # Ignore generated info.json from pytest | ||
2 | info.json | ||
diff --git a/lib/python/qmk/tests/test_cli_commands.py b/lib/python/qmk/tests/test_cli_commands.py index 68f8ed604..0b840b466 100644 --- a/lib/python/qmk/tests/test_cli_commands.py +++ b/lib/python/qmk/tests/test_cli_commands.py | |||
@@ -45,8 +45,9 @@ def test_config(): | |||
45 | 45 | ||
46 | 46 | ||
47 | def test_kle2json(): | 47 | def test_kle2json(): |
48 | result = check_subcommand('kle2json', 'kle.txt', '-f') | 48 | result = check_subcommand('kle2json', 'lib/python/qmk/tests/kle.txt', '-f') |
49 | check_returncode(result) | 49 | check_returncode(result) |
50 | assert 'Wrote out' in result.stdout | ||
50 | 51 | ||
51 | 52 | ||
52 | def test_doctor(): | 53 | def test_doctor(): |