summaryrefslogtreecommitdiff
path: root/lib/python/qmk/cli
diff options
context:
space:
mode:
authorJoel Challis <git@zvecr.com>2024-03-14 10:24:24 +0000
committerGitHub <noreply@github.com>2024-03-14 21:24:24 +1100
commit6720e9c58c3a239ff0de4be1ff2ad075a0b2c248 (patch)
treecd4dba192787a4d36fa592d25422bdc9776a1da0 /lib/python/qmk/cli
parentaea414fd828964c13301191b88a56174f85fad8d (diff)
`qmk new-keyboard` - detach community layout when selecting "none of the above" (#20405)
Diffstat (limited to 'lib/python/qmk/cli')
-rw-r--r--lib/python/qmk/cli/new/keyboard.py18
1 files changed, 14 insertions, 4 deletions
diff --git a/lib/python/qmk/cli/new/keyboard.py b/lib/python/qmk/cli/new/keyboard.py
index 700afc96a6..37bf2923d6 100644
--- a/lib/python/qmk/cli/new/keyboard.py
+++ b/lib/python/qmk/cli/new/keyboard.py
@@ -74,6 +74,10 @@ def replace_placeholders(src, dest, tokens):
74 dest.write_text(content) 74 dest.write_text(content)
75 75
76 76
77def replace_string(src, token, value):
78 src.write_text(src.read_text().replace(token, value))
79
80
77def augment_community_info(src, dest): 81def augment_community_info(src, dest):
78 """Splice in any additional data into info.json 82 """Splice in any additional data into info.json
79 """ 83 """
@@ -218,6 +222,11 @@ def new_keyboard(cli):
218 else: 222 else:
219 bootloader = select_default_bootloader(mcu) 223 bootloader = select_default_bootloader(mcu)
220 224
225 detach_layout = False
226 if default_layout == 'none of the above':
227 default_layout = "ortho_4x4"
228 detach_layout = True
229
221 tokens = { # Comment here is to force multiline formatting 230 tokens = { # Comment here is to force multiline formatting
222 'YEAR': str(date.today().year), 231 'YEAR': str(date.today().year),
223 'KEYBOARD': kb_name, 232 'KEYBOARD': kb_name,
@@ -233,10 +242,6 @@ def new_keyboard(cli):
233 for key, value in tokens.items(): 242 for key, value in tokens.items():
234 cli.echo(f" {key.ljust(10)}: {value}") 243 cli.echo(f" {key.ljust(10)}: {value}")
235 244
236 # TODO: detach community layout and rename to just "LAYOUT"
237 if default_layout == 'none of the above':
238 default_layout = "ortho_4x4"
239
240 # begin with making the deepest folder in the tree 245 # begin with making the deepest folder in the tree
241 keymaps_path = keyboard(kb_name) / 'keymaps/' 246 keymaps_path = keyboard(kb_name) / 'keymaps/'
242 keymaps_path.mkdir(parents=True) 247 keymaps_path.mkdir(parents=True)
@@ -253,6 +258,11 @@ def new_keyboard(cli):
253 community_info = Path(COMMUNITY / f'{default_layout}/info.json') 258 community_info = Path(COMMUNITY / f'{default_layout}/info.json')
254 augment_community_info(community_info, keyboard(kb_name) / 'keyboard.json') 259 augment_community_info(community_info, keyboard(kb_name) / 'keyboard.json')
255 260
261 # detach community layout and rename to just "LAYOUT"
262 if detach_layout:
263 replace_string(keyboard(kb_name) / 'keyboard.json', 'LAYOUT_ortho_4x4', 'LAYOUT')
264 replace_string(keymaps_path / 'default/keymap.c', 'LAYOUT_ortho_4x4', 'LAYOUT')
265
256 cli.log.info(f'{{fg_green}}Created a new keyboard called {{fg_cyan}}{kb_name}{{fg_green}}.{{fg_reset}}') 266 cli.log.info(f'{{fg_green}}Created a new keyboard called {{fg_cyan}}{kb_name}{{fg_green}}.{{fg_reset}}')
257 cli.log.info(f"Build Command: {{fg_yellow}}qmk compile -kb {kb_name} -km default{{fg_reset}}.") 267 cli.log.info(f"Build Command: {{fg_yellow}}qmk compile -kb {kb_name} -km default{{fg_reset}}.")
258 cli.log.info(f'Project Location: {{fg_cyan}}{QMK_FIRMWARE}/{keyboard(kb_name)}{{fg_reset}},') 268 cli.log.info(f'Project Location: {{fg_cyan}}{QMK_FIRMWARE}/{keyboard(kb_name)}{{fg_reset}},')