keyboard stuff
1"""Command to search through all keyboards and keymaps for a given search criteria.
2"""
3import os
4from milc import cli
5from qmk.search import filter_help, search_keymap_targets
6from qmk.util import maybe_exit_config
7
8
9@cli.argument(
10 '-f',
11 '--filter',
12 arg_only=True,
13 action='append',
14 default=[],
15 help= # noqa: `format-python` and `pytest` don't agree here.
16 f"Filter the list of keyboards based on their info.json data. Accepts the formats key=value, function(key), or function(key,value), eg. 'features.rgblight=true'. Valid functions are {filter_help()}. May be passed multiple times; all filters need to match. Value may include wildcards such as '*' and '?'." # noqa: `format-python` and `pytest` don't agree here.
17)
18@cli.argument('-p', '--print', arg_only=True, action='append', default=[], help="For each matched target, print the value of the supplied info.json key. May be passed multiple times.")
19@cli.argument('-km', '--keymap', type=str, default='default', help="The keymap name to build. Default is 'default'.")
20@cli.subcommand('Find builds which match supplied search criteria.')
21def find(cli):
22 """Search through all keyboards and keymaps for a given search criteria.
23 """
24 os.environ.setdefault('SKIP_SCHEMA_VALIDATION', '1')
25 maybe_exit_config(should_exit=False, should_reraise=True)
26
27 targets = search_keymap_targets([('all', cli.config.find.keymap)], cli.args.filter)
28 for target in sorted(targets, key=lambda t: (t.keyboard, t.keymap)):
29 print(f'{target}')
30
31 for key in cli.args.print:
32 print(f' {key}={target.dotty.get(key, None)}')