Skip to content

Commit

Permalink
Align 'qmk lint' argument handling (#23297)
Browse files Browse the repository at this point in the history
  • Loading branch information
zvecr authored May 1, 2024
1 parent 7b9a1ac commit 54c1ae5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
35 changes: 15 additions & 20 deletions lib/python/qmk/cli/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

from qmk.decorators import automagic_keyboard, automagic_keymap
from qmk.info import info_json
from qmk.keyboard import keyboard_completer, list_keyboards
from qmk.keyboard import keyboard_completer, keyboard_folder_or_all, is_all_keyboards, list_keyboards
from qmk.keymap import locate_keymap, list_keymaps
from qmk.path import is_keyboard, keyboard
from qmk.path import keyboard
from qmk.git import git_get_ignored_files
from qmk.c_parse import c_source_files

Expand Down Expand Up @@ -198,39 +198,34 @@ def keyboard_check(kb):


@cli.argument('--strict', action='store_true', help='Treat warnings as errors')
@cli.argument('-kb', '--keyboard', completer=keyboard_completer, help='Comma separated list of keyboards to check')
@cli.argument('-kb', '--keyboard', action='append', type=keyboard_folder_or_all, completer=keyboard_completer, help='Keyboard to check. May be passed multiple times.')
@cli.argument('-km', '--keymap', help='The keymap to check')
@cli.argument('--all-kb', action='store_true', arg_only=True, help='Check all keyboards')
@cli.argument('--all-km', action='store_true', arg_only=True, help='Check all keymaps')
@cli.subcommand('Check keyboard and keymap for common mistakes.')
@automagic_keyboard
@automagic_keymap
def lint(cli):
"""Check keyboard and keymap for common mistakes.
"""
failed = []

# Determine our keyboard list
if cli.args.all_kb:
if cli.args.keyboard:
cli.log.warning('Both --all-kb and --keyboard passed, --all-kb takes precedence.')

keyboard_list = list_keyboards()
elif not cli.config.lint.keyboard:
cli.log.error('Missing required arguments: --keyboard or --all-kb')
if not cli.config.lint.keyboard:
cli.log.error('Missing required arguments: --keyboard')
cli.print_help()
return False

if isinstance(cli.config.lint.keyboard, str):
# if provided via config - string not array
keyboard_list = [cli.config.lint.keyboard]
elif is_all_keyboards(cli.args.keyboard[0]):
keyboard_list = list_keyboards()
else:
keyboard_list = cli.config.lint.keyboard.split(',')
keyboard_list = cli.config.lint.keyboard

failed = []

# Lint each keyboard
for kb in keyboard_list:
if not is_keyboard(kb):
cli.log.error('No such keyboard: %s', kb)
continue

# Determine keymaps to also check
if cli.args.all_km:
if cli.args.keymap == 'all':
keymaps = list_keymaps(kb)
elif cli.config.lint.keymap:
keymaps = {cli.config.lint.keymap}
Expand Down
2 changes: 2 additions & 0 deletions lib/python/qmk/keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ def find_keyboard_from_dir():
keymap_index = len(current_path.parts) - current_path.parts.index('keymaps') - 1
current_path = current_path.parents[keymap_index]

current_path = resolve_keyboard(current_path)

if qmk.path.is_keyboard(current_path):
return str(current_path)

Expand Down

0 comments on commit 54c1ae5

Please sign in to comment.