1
0
Fork 0

CLI: update subcommands to use return instead of exit() (#10323)

This commit is contained in:
Ryan 2020-10-07 10:46:10 +11:00 committed by GitHub
parent 2013f63134
commit 2c9ffd4739
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 20 additions and 18 deletions

View file

@ -364,3 +364,5 @@ def doctor(cli):
else: else:
cli.log.info('{fg_yellow}Problems detected, please fix these problems before proceeding.') cli.log.info('{fg_yellow}Problems detected, please fix these problems before proceeding.')
# FIXME(skullydazed/unclaimed): Link to a document about troubleshooting, or discord or something # FIXME(skullydazed/unclaimed): Link to a document about troubleshooting, or discord or something
return ok

View file

@ -134,11 +134,11 @@ def info(cli):
if not cli.config.info.keyboard: if not cli.config.info.keyboard:
cli.log.error('Missing paramater: --keyboard') cli.log.error('Missing paramater: --keyboard')
cli.subcommands['info'].print_help() cli.subcommands['info'].print_help()
exit(1) return False
if not is_keyboard(cli.config.info.keyboard): if not is_keyboard(cli.config.info.keyboard):
cli.log.error('Invalid keyboard: "%s"', cli.config.info.keyboard) cli.log.error('Invalid keyboard: "%s"', cli.config.info.keyboard)
exit(1) return False
# Build the info.json file # Build the info.json file
kb_info_json = info_json(cli.config.info.keyboard) kb_info_json = info_json(cli.config.info.keyboard)
@ -146,13 +146,10 @@ def info(cli):
# Output in the requested format # Output in the requested format
if cli.args.format == 'json': if cli.args.format == 'json':
print(json.dumps(kb_info_json)) print(json.dumps(kb_info_json))
exit() elif cli.args.format == 'text':
if cli.args.format == 'text':
print_text_output(kb_info_json) print_text_output(kb_info_json)
elif cli.args.format == 'friendly': elif cli.args.format == 'friendly':
print_friendly_output(kb_info_json) print_friendly_output(kb_info_json)
else: else:
cli.log.error('Unknown format: %s', cli.args.format) cli.log.error('Unknown format: %s', cli.args.format)
return False

View file

@ -13,4 +13,4 @@ def json_keymap(cli):
"""Renamed to `qmk json2c`. """Renamed to `qmk json2c`.
""" """
cli.log.error('This command has been renamed to `qmk json2c`.') cli.log.error('This command has been renamed to `qmk json2c`.')
exit(1) return False

View file

@ -22,12 +22,12 @@ def json2c(cli):
# TODO(skullydazed/anyone): Read file contents from STDIN # TODO(skullydazed/anyone): Read file contents from STDIN
cli.log.error('Reading from STDIN is not (yet) supported.') cli.log.error('Reading from STDIN is not (yet) supported.')
cli.print_usage() cli.print_usage()
exit(1) return False
if not cli.args.filename.exists(): if not cli.args.filename.exists():
cli.log.error('JSON file does not exist!') cli.log.error('JSON file does not exist!')
cli.print_usage() cli.print_usage()
exit(1) return False
# Environment processing # Environment processing
if cli.args.output and cli.args.output.name == '-': if cli.args.output and cli.args.output.name == '-':

View file

@ -37,7 +37,8 @@ def kle2json(cli):
file_path = Path(os.environ['ORIG_CWD'], cli.args.filename) file_path = Path(os.environ['ORIG_CWD'], cli.args.filename)
# Check for valid file_path for more graceful failure # Check for valid file_path for more graceful failure
if not file_path.exists(): if not file_path.exists():
return cli.log.error('File {fg_cyan}%s{style_reset_all} was not found.', file_path) cli.log.error('File {fg_cyan}%s{style_reset_all} was not found.', file_path)
return False
out_path = file_path.parent out_path = file_path.parent
raw_code = file_path.open().read() raw_code = file_path.open().read()
# Check if info.json exists, allow overwrite with force # Check if info.json exists, allow overwrite with force
@ -50,8 +51,7 @@ def kle2json(cli):
except Exception as e: except Exception as e:
cli.log.error('Could not parse KLE raw data: %s', raw_code) cli.log.error('Could not parse KLE raw data: %s', raw_code)
cli.log.exception(e) cli.log.exception(e)
# FIXME: This should be better return False
return cli.log.error('Could not parse KLE raw data.')
keyboard = OrderedDict( keyboard = OrderedDict(
keyboard_name=kle.name, keyboard_name=kle.name,
url='', url='',

View file

@ -15,7 +15,7 @@ def list_keymaps(cli):
""" """
if not is_keyboard(cli.config.list_keymaps.keyboard): if not is_keyboard(cli.config.list_keymaps.keyboard):
cli.log.error('Keyboard %s does not exist!', cli.config.list_keymaps.keyboard) cli.log.error('Keyboard %s does not exist!', cli.config.list_keymaps.keyboard)
exit(1) return False
for name in qmk.keymap.list_keymaps(cli.config.list_keymaps.keyboard): for name in qmk.keymap.list_keymaps(cli.config.list_keymaps.keyboard):
print(name) print(name)

View file

@ -29,15 +29,15 @@ def new_keymap(cli):
# check directories # check directories
if not kb_path.exists(): if not kb_path.exists():
cli.log.error('Keyboard %s does not exist!', kb_path) cli.log.error('Keyboard %s does not exist!', kb_path)
exit(1) return False
if not keymap_path_default.exists(): if not keymap_path_default.exists():
cli.log.error('Keyboard default %s does not exist!', keymap_path_default) cli.log.error('Keyboard default %s does not exist!', keymap_path_default)
exit(1) return False
if keymap_path_new.exists(): if keymap_path_new.exists():
cli.log.error('Keymap %s already exists!', keymap_path_new) cli.log.error('Keymap %s already exists!', keymap_path_new)
exit(1) return False
# create user directory with default keymap files # create user directory with default keymap files
shutil.copytree(keymap_path_default, keymap_path_new, symlinks=True) shutil.copytree(keymap_path_default, keymap_path_new, symlinks=True)

2
lib/python/qmk/tests/.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
# Ignore generated info.json from pytest
info.json

View file

@ -45,8 +45,9 @@ def test_config():
def test_kle2json(): def test_kle2json():
result = check_subcommand('kle2json', 'kle.txt', '-f') result = check_subcommand('kle2json', 'lib/python/qmk/tests/kle.txt', '-f')
check_returncode(result) check_returncode(result)
assert 'Wrote out' in result.stdout
def test_doctor(): def test_doctor():