Skip to content

Commit cdd6fea

Browse files
committed
add filtering option
1 parent 7140008 commit cdd6fea

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

tools/board_stubs/circuitpython_setboard/__init__.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,26 @@ def set_board():
4040
usage="Install CircuitPython board-specific stubs",
4141
)
4242
parser.add_argument("chosen_board", help="selected board", nargs="?")
43-
parser.add_argument("-l", "--list", help="show available boards", action="store_true")
43+
parser.add_argument(
44+
"-l",
45+
"--list",
46+
help=f"show available boards. can filter eg: '{__name__} -l feather'",
47+
action="store_true",
48+
)
4449

4550
args = parser.parse_args()
4651

4752
if args.list:
4853
port_boards: defaultdict[str, list[str]] = defaultdict(list)
4954

5055
for board in resources.files("board_definitions").iterdir():
56+
# if we receive both the list flag and a board name, use it as filter
57+
if (
58+
args.chosen_board is not None
59+
and args.chosen_board.lower() not in board.name.lower()
60+
):
61+
continue
62+
5163
# NOTE: For the hand-crafted finding of port in the docstring, its
5264
# format is assumed to be:
5365
#
@@ -65,6 +77,10 @@ def set_board():
6577

6678
port_boards[port].append(board.name)
6779

80+
if not port_boards:
81+
sys.stdout.write("Nothing found, check out your filter.\n")
82+
sys.exit(0)
83+
6884
sys.stdout.write("Available boards are: \n")
6985
# sort by port name
7086
for port, boards in sorted(port_boards.items(), key=lambda kv: kv[0]):

0 commit comments

Comments
 (0)