summaryrefslogtreecommitdiff
path: root/lib/python/qmk/cli/new
diff options
context:
space:
mode:
authorJoel Challis <git@zvecr.com>2022-12-03 12:04:06 +0000
committerGitHub <noreply@github.com>2022-12-03 12:04:06 +0000
commit32dabd5320b2914bb5631bd6f95b8cd7ca4419e7 (patch)
treea296b5c212feff33d8477e5855cf0213779b14d3 /lib/python/qmk/cli/new
parent82760bcea65d1f9e8f39aaca06f1d3b4e22a1f64 (diff)
Align new-keymap with new-keyboard (#19229)
Diffstat (limited to 'lib/python/qmk/cli/new')
-rwxr-xr-xlib/python/qmk/cli/new/keymap.py56
1 files changed, 39 insertions, 17 deletions
diff --git a/lib/python/qmk/cli/new/keymap.py b/lib/python/qmk/cli/new/keymap.py
index 60cb743cb6..e7823bc46d 100755
--- a/lib/python/qmk/cli/new/keymap.py
+++ b/lib/python/qmk/cli/new/keymap.py
@@ -1,12 +1,32 @@
1"""This script automates the copying of the default keymap into your own keymap. 1"""This script automates the copying of the default keymap into your own keymap.
2""" 2"""
3import shutil 3import shutil
4from pathlib import Path
5 4
6import qmk.path 5from milc import cli
6from milc.questions import question
7
8from qmk.path import is_keyboard, keymap
9from qmk.git import git_get_username
7from qmk.decorators import automagic_keyboard, automagic_keymap 10from qmk.decorators import automagic_keyboard, automagic_keymap
8from qmk.keyboard import keyboard_completer, keyboard_folder 11from qmk.keyboard import keyboard_completer, keyboard_folder
9from milc import cli 12
13
14def prompt_keyboard():
15 prompt = """{fg_yellow}Select Keyboard{style_reset_all}
16If you`re unsure you can view a full list of supported keyboards with {fg_yellow}qmk list-keyboards{style_reset_all}.
17
18Keyboard Name? """
19
20 return question(prompt)
21
22
23def prompt_user():
24 prompt = """
25{fg_yellow}Name Your Keymap{style_reset_all}
26Used for maintainer, copyright, etc
27
28Your GitHub Username? """
29 return question(prompt, default=git_get_username())
10 30
11 31
12@cli.argument('-kb', '--keyboard', type=keyboard_folder, completer=keyboard_completer, help='Specify keyboard name. Example: 1upkeyboards/1up60hse') 32@cli.argument('-kb', '--keyboard', type=keyboard_folder, completer=keyboard_completer, help='Specify keyboard name. Example: 1upkeyboards/1up60hse')
@@ -17,32 +37,34 @@ from milc import cli
17def new_keymap(cli): 37def new_keymap(cli):
18 """Creates a new keymap for the keyboard of your choosing. 38 """Creates a new keymap for the keyboard of your choosing.
19 """ 39 """
20 # ask for user input if keyboard or keymap was not provided in the command line 40 cli.log.info('{style_bright}Generating a new keymap{style_normal}')
21 keyboard = cli.config.new_keymap.keyboard if cli.config.new_keymap.keyboard else input("Keyboard Name: ") 41 cli.echo('')
22 keymap = cli.config.new_keymap.keymap if cli.config.new_keymap.keymap else input("Keymap Name: ")
23 42
24 # generate keymap paths 43 # ask for user input if keyboard or keymap was not provided in the command line
25 kb_path = Path('keyboards') / keyboard 44 kb_name = cli.config.new_keymap.keyboard if cli.config.new_keymap.keyboard else prompt_keyboard()
26 keymap_path = qmk.path.keymap(keyboard) 45 user_name = cli.config.new_keymap.keymap if cli.config.new_keymap.keymap else prompt_user()
27 keymap_path_default = keymap_path / 'default'
28 keymap_path_new = keymap_path / keymap
29 46
30 # check directories 47 # check directories
31 if not kb_path.exists(): 48 if not is_keyboard(kb_name):
32 cli.log.error('Keyboard %s does not exist!', kb_path) 49 cli.log.error(f'Keyboard {{fg_cyan}}{kb_name}{{fg_reset}} does not exist! Please choose a valid name.')
33 return False 50 return False
34 51
52 # generate keymap paths
53 km_path = keymap(kb_name)
54 keymap_path_default = km_path / 'default'
55 keymap_path_new = km_path / user_name
56
35 if not keymap_path_default.exists(): 57 if not keymap_path_default.exists():
36 cli.log.error('Keyboard default %s does not exist!', keymap_path_default) 58 cli.log.error(f'Default keymap {{fg_cyan}}{keymap_path_default}{{fg_reset}} does not exist!')
37 return False 59 return False
38 60
39 if keymap_path_new.exists(): 61 if keymap_path_new.exists():
40 cli.log.error('Keymap %s already exists!', keymap_path_new) 62 cli.log.error(f'Keymap {{fg_cyan}}{user_name}{{fg_reset}} already exists! Please choose a different name.')
41 return False 63 return False
42 64
43 # create user directory with default keymap files 65 # create user directory with default keymap files
44 shutil.copytree(keymap_path_default, keymap_path_new, symlinks=True) 66 shutil.copytree(keymap_path_default, keymap_path_new, symlinks=True)
45 67
46 # end message to user 68 # end message to user
47 cli.log.info("%s keymap directory created in: %s", keymap, keymap_path_new) 69 cli.log.info(f'{{fg_green}}Created a new keymap called {{fg_cyan}}{user_name}{{fg_green}} in: {{fg_cyan}}{keymap_path_new}.{{fg_reset}}')
48 cli.log.info("Compile a firmware with your new keymap by typing: \n\n\tqmk compile -kb %s -km %s\n", keyboard, keymap) 70 cli.log.info(f"Compile a firmware with your new keymap by typing: {{fg_yellow}}qmk compile -kb {kb_name} -km {user_name}{{fg_reset}}.")