find.py 1.4 KB

123456789101112131415161718192021222324252627
  1. """Command to search through all keyboards and keymaps for a given search criteria.
  2. """
  3. from milc import cli
  4. from qmk.search import search_keymap_targets
  5. @cli.argument(
  6. '-f',
  7. '--filter',
  8. arg_only=True,
  9. action='append',
  10. default=[],
  11. help= # noqa: `format-python` and `pytest` don't agree here.
  12. "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 'absent', 'contains', 'exists' and 'length'. 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.
  13. )
  14. @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.")
  15. @cli.argument('-km', '--keymap', type=str, default='default', help="The keymap name to build. Default is 'default'.")
  16. @cli.subcommand('Find builds which match supplied search criteria.')
  17. def find(cli):
  18. """Search through all keyboards and keymaps for a given search criteria.
  19. """
  20. targets = search_keymap_targets([('all', cli.config.find.keymap)], cli.args.filter)
  21. for target in sorted(targets, key=lambda t: (t.keyboard, t.keymap)):
  22. print(f'{target}')
  23. for key in cli.args.print:
  24. print(f' {key}={target.dotty.get(key, None)}')