Skip to content

Commit 933efe0

Browse files
committed
add --list to stubs setboard
1 parent 9ab8831 commit 933efe0

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed
Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,42 @@
11
# SPDX-FileCopyrightText: 2024 Tim Cocks
22
#
33
# SPDX-License-Identifier: MIT
4-
from importlib import resources
5-
import os
4+
import argparse
65
import sys
76
import shutil
7+
from importlib import resources
88

99

1010
def set_board():
11-
if len(sys.argv) != 2:
12-
print(f"Incorrect args. Please call with: 'circuitpython_setboard chosen_board'")
13-
return
11+
parser = argparse.ArgumentParser(
12+
prog=__name__,
13+
usage="Install CircuitPython board-specific stubs",
14+
)
15+
parser.add_argument("chosen_board", help="selected board", nargs="?")
16+
parser.add_argument("-l", "--list", help="show available boards", action="store_true")
17+
18+
args = parser.parse_args()
19+
20+
if args.list:
21+
sys.stdout.write("Available boards are: \n")
22+
23+
for board in resources.files("board_definitions").iterdir():
24+
sys.stdout.write(f"{board.name}\n")
25+
26+
sys.exit(0)
27+
28+
if args.chosen_board is None:
29+
sys.stderr.write("Must select a board")
30+
sys.exit(1)
1431

15-
chosen_board = sys.argv[1]
16-
print(f"setting board: {chosen_board}")
32+
print(f"setting board: {args.chosen_board}")
1733

1834
board_stubs_file = resources.files("board-stubs").joinpath("__init__.pyi")
19-
board_definitions_path = resources.files("board_definitions").joinpath(chosen_board)
35+
board_definitions_path = resources.files("board_definitions").joinpath(args.chosen_board)
2036
board_definitions_file = board_definitions_path.joinpath("__init__.pyi")
2137

2238
if not board_definitions_file.is_file():
23-
print(f"Board: '{chosen_board}' was not found")
24-
return
39+
print(f"Board: '{args.chosen_board}' was not found")
40+
sys.exit(1)
2541

2642
shutil.copyfile(board_definitions_file, board_stubs_file)

0 commit comments

Comments
 (0)