From 327d89c09f2789fb1e9a1d624685a308e93e6693 Mon Sep 17 00:00:00 2001 From: zvecr Date: Sat, 7 Jan 2023 17:30:53 +0000 Subject: [PATCH 1/2] Validate keymap arg --- lib/python/qmk/cli/compile.py | 17 ++++++++++++++++- lib/python/qmk/cli/flash.py | 17 ++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/lib/python/qmk/cli/compile.py b/lib/python/qmk/cli/compile.py index 9e7629906f32..dbc2a948ab3b 100755 --- a/lib/python/qmk/cli/compile.py +++ b/lib/python/qmk/cli/compile.py @@ -10,7 +10,17 @@ from qmk.decorators import automagic_keyboard, automagic_keymap from qmk.commands import compile_configurator_json, create_make_command, parse_configurator_json, build_environment from qmk.keyboard import keyboard_completer, keyboard_folder -from qmk.keymap import keymap_completer +from qmk.keymap import keymap_completer, locate_keymap + + +def _is_keymap_target(keyboard, keymap): + if keymap == 'all': + return True + + if locate_keymap(keyboard, keymap): + return True + + return False @cli.argument('filename', nargs='?', arg_only=True, type=qmk.path.FileType('r'), completer=FilesCompleter('.json'), help='The configurator export to compile') @@ -43,6 +53,11 @@ def compile(cli): elif cli.config.compile.keyboard and cli.config.compile.keymap: # Generate the make command for a specific keyboard/keymap. + if not _is_keymap_target(cli.config.compile.keyboard, cli.config.compile.keymap): + cli.log.error('Invalid keymap argument.') + cli.print_help() + return False + if cli.args.clean: commands.append(create_make_command(cli.config.compile.keyboard, cli.config.compile.keymap, 'clean', **envs)) commands.append(create_make_command(cli.config.compile.keyboard, cli.config.compile.keymap, parallel=cli.config.compile.parallel, **envs)) diff --git a/lib/python/qmk/cli/flash.py b/lib/python/qmk/cli/flash.py index 52defb5f0d3c..1c4cd8f293b8 100644 --- a/lib/python/qmk/cli/flash.py +++ b/lib/python/qmk/cli/flash.py @@ -11,10 +11,20 @@ from qmk.decorators import automagic_keyboard, automagic_keymap from qmk.commands import compile_configurator_json, create_make_command, parse_configurator_json, build_environment from qmk.keyboard import keyboard_completer, keyboard_folder -from qmk.keymap import keymap_completer +from qmk.keymap import keymap_completer, locate_keymap from qmk.flashers import flasher +def _is_keymap_target(keyboard, keymap): + if keymap == 'all': + return True + + if locate_keymap(keyboard, keymap): + return True + + return False + + def _list_bootloaders(): """Prints the available bootloaders listed in docs.qmk.fm. """ @@ -98,6 +108,11 @@ def flash(cli): elif cli.config.flash.keyboard and cli.config.flash.keymap: # Generate the make command for a specific keyboard/keymap. + if not _is_keymap_target(cli.config.flash.keyboard, cli.config.flash.keymap): + cli.log.error('Invalid keymap argument.') + cli.print_help() + return False + if cli.args.clean: commands.append(create_make_command(cli.config.flash.keyboard, cli.config.flash.keymap, 'clean', **envs)) commands.append(create_make_command(cli.config.flash.keyboard, cli.config.flash.keymap, cli.args.bootloader, parallel=cli.config.flash.parallel, **envs)) From c79dd1694b94b90efcc62e534dddab4ed0aba3be Mon Sep 17 00:00:00 2001 From: zvecr Date: Sat, 7 Jan 2023 17:36:27 +0000 Subject: [PATCH 2/2] lint --- lib/python/qmk/cli/compile.py | 2 +- lib/python/qmk/cli/flash.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/python/qmk/cli/compile.py b/lib/python/qmk/cli/compile.py index dbc2a948ab3b..f43e5f32dea9 100755 --- a/lib/python/qmk/cli/compile.py +++ b/lib/python/qmk/cli/compile.py @@ -19,7 +19,7 @@ def _is_keymap_target(keyboard, keymap): if locate_keymap(keyboard, keymap): return True - + return False diff --git a/lib/python/qmk/cli/flash.py b/lib/python/qmk/cli/flash.py index 1c4cd8f293b8..8724f26889b2 100644 --- a/lib/python/qmk/cli/flash.py +++ b/lib/python/qmk/cli/flash.py @@ -21,7 +21,7 @@ def _is_keymap_target(keyboard, keymap): if locate_keymap(keyboard, keymap): return True - + return False