diff options
Diffstat (limited to 'lib/python/qmk/cli/list/keyboards.py')
| -rw-r--r-- | lib/python/qmk/cli/list/keyboards.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/python/qmk/cli/list/keyboards.py b/lib/python/qmk/cli/list/keyboards.py new file mode 100644 index 0000000000..53a7af75c6 --- /dev/null +++ b/lib/python/qmk/cli/list/keyboards.py | |||
| @@ -0,0 +1,26 @@ | |||
| 1 | """List the keyboards currently defined within QMK | ||
| 2 | """ | ||
| 3 | import os | ||
| 4 | import re | ||
| 5 | import glob | ||
| 6 | |||
| 7 | from milc import cli | ||
| 8 | |||
| 9 | @cli.subcommand("List the keyboards currently defined within QMK") | ||
| 10 | def list_keyboards(cli): | ||
| 11 | """List the keyboards currently defined within QMK | ||
| 12 | """ | ||
| 13 | |||
| 14 | base_path = os.path.join(os.getcwd(), "keyboards") + os.path.sep | ||
| 15 | kb_path_wildcard = os.path.join(base_path, "**", "rules.mk") | ||
| 16 | |||
| 17 | # find everywhere we have rules.mk where keymaps isn't in the path | ||
| 18 | paths = [path for path in glob.iglob(kb_path_wildcard, recursive=True) if 'keymaps' not in path] | ||
| 19 | |||
| 20 | # strip the keyboard directory path prefix and rules.mk suffix and alphabetize | ||
| 21 | find_name = lambda path: path.replace(base_path, "").replace(os.path.sep + "rules.mk", "") | ||
| 22 | names = sorted(map(find_name, paths)) | ||
| 23 | |||
| 24 | for name in names: | ||
| 25 | # We echo instead of cli.log.info to allow easier piping of this output | ||
| 26 | cli.echo(name) | ||
