aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan McClain <dan@danmcclain.net>2019-10-07 14:32:30 -0400
committernoroadsleft <18669334+noroadsleft@users.noreply.github.com>2019-10-07 11:32:30 -0700
commitf04e58dad6f56cdbd5d369c9e00405dcdb47c8ea (patch)
tree3731766a019c84f9a080cade3f4eee4460473341
parentd9b056486bf62f4751999d926fb3f8aad6d0c821 (diff)
downloadqmk_firmware-f04e58dad6f56cdbd5d369c9e00405dcdb47c8ea.tar.gz
qmk_firmware-f04e58dad6f56cdbd5d369c9e00405dcdb47c8ea.zip
[CLI] Add `qmk list_keyboards` (#6927)
`list_keyboards` replicates the `make list-keyboards` by globbing for all paths that include `rules.mk` and then removing the paths that include `keymaps`. This basis of this cli command could be reused in the future as a util, but is not done so here since this would be the only place that would use it currently Resolves #6911
-rw-r--r--docs/cli.md10
-rw-r--r--lib/python/qmk/cli/__init__.py1
-rw-r--r--lib/python/qmk/cli/list/__init__.py1
-rw-r--r--lib/python/qmk/cli/list/keyboards.py26
-rw-r--r--lib/python/qmk/tests/test_cli_commands.py8
5 files changed, 46 insertions, 0 deletions
diff --git a/docs/cli.md b/docs/cli.md
index fe86cac1f..6ffe03365 100644
--- a/docs/cli.md
+++ b/docs/cli.md
@@ -115,6 +115,16 @@ This command examines your environment and alerts you to potential build or flas
115qmk doctor 115qmk doctor
116``` 116```
117 117
118## `qmk list_keyboards`
119
120This command lists all the keyboards currently defined in `qmk_firmware`
121
122**Usage**:
123
124```
125qmk list_keyboards
126```
127
118## `qmk new-keymap` 128## `qmk new-keymap`
119 129
120This command creates a new keymap based on a keyboard's existing default keymap. 130This command creates a new keymap based on a keyboard's existing default keymap.
diff --git a/lib/python/qmk/cli/__init__.py b/lib/python/qmk/cli/__init__.py
index fb4e0ecb4..e982a75fc 100644
--- a/lib/python/qmk/cli/__init__.py
+++ b/lib/python/qmk/cli/__init__.py
@@ -8,6 +8,7 @@ from . import config
8from . import doctor 8from . import doctor
9from . import hello 9from . import hello
10from . import json 10from . import json
11from . import list
11from . import new 12from . import new
12from . import pyformat 13from . import pyformat
13from . import pytest 14from . import pytest
diff --git a/lib/python/qmk/cli/list/__init__.py b/lib/python/qmk/cli/list/__init__.py
new file mode 100644
index 000000000..c36ba6954
--- /dev/null
+++ b/lib/python/qmk/cli/list/__init__.py
@@ -0,0 +1 @@
from . import keyboards
diff --git a/lib/python/qmk/cli/list/keyboards.py b/lib/python/qmk/cli/list/keyboards.py
new file mode 100644
index 000000000..53a7af75c
--- /dev/null
+++ b/lib/python/qmk/cli/list/keyboards.py
@@ -0,0 +1,26 @@
1"""List the keyboards currently defined within QMK
2"""
3import os
4import re
5import glob
6
7from milc import cli
8
9@cli.subcommand("List the keyboards currently defined within QMK")
10def 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)
diff --git a/lib/python/qmk/tests/test_cli_commands.py b/lib/python/qmk/tests/test_cli_commands.py
index 2fc6e0f72..c9d632517 100644
--- a/lib/python/qmk/tests/test_cli_commands.py
+++ b/lib/python/qmk/tests/test_cli_commands.py
@@ -37,3 +37,11 @@ def test_pyformat():
37 result = check_subcommand('pyformat') 37 result = check_subcommand('pyformat')
38 assert result.returncode == 0 38 assert result.returncode == 0
39 assert 'Successfully formatted the python code' in result.stderr 39 assert 'Successfully formatted the python code' in result.stderr
40
41
42def test_list_keyboards():
43 result = check_subcommand('list_keyboards')
44 assert result.returncode == 0
45 # check to see if a known keyboard is returned
46 # this will fail if handwired/onekey/pytest is removed
47 assert 'handwired/onekey/pytest' in result.stdout