summaryrefslogtreecommitdiff
path: root/lib/python/qmk/cli
diff options
context:
space:
mode:
Diffstat (limited to 'lib/python/qmk/cli')
-rwxr-xr-xlib/python/qmk/cli/new/keymap.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/python/qmk/cli/new/keymap.py b/lib/python/qmk/cli/new/keymap.py
index d4339bc9ef..f1df05636c 100755
--- a/lib/python/qmk/cli/new/keymap.py
+++ b/lib/python/qmk/cli/new/keymap.py
@@ -1,5 +1,6 @@
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 re
3import shutil 4import shutil
4 5
5from milc import cli 6from milc import cli
@@ -13,6 +14,13 @@ from qmk.keyboard import keyboard_completer, keyboard_folder
13from qmk.userspace import UserspaceDefs 14from qmk.userspace import UserspaceDefs
14 15
15 16
17def validate_keymap_name(name):
18 """Returns True if the given keymap name contains only a-z, 0-9 and underscore characters.
19 """
20 regex = re.compile(r'^[a-zA-Z0-9][a-zA-Z0-9_]+$')
21 return bool(regex.match(name))
22
23
16def prompt_keyboard(): 24def prompt_keyboard():
17 prompt = """{fg_yellow}Select Keyboard{style_reset_all} 25 prompt = """{fg_yellow}Select Keyboard{style_reset_all}
18If you`re unsure you can view a full list of supported keyboards with {fg_yellow}qmk list-keyboards{style_reset_all}. 26If you`re unsure you can view a full list of supported keyboards with {fg_yellow}qmk list-keyboards{style_reset_all}.
@@ -60,6 +68,10 @@ def new_keymap(cli):
60 cli.log.error(f'Default keymap {{fg_cyan}}{keymap_path_default}{{fg_reset}} does not exist!') 68 cli.log.error(f'Default keymap {{fg_cyan}}{keymap_path_default}{{fg_reset}} does not exist!')
61 return False 69 return False
62 70
71 if not validate_keymap_name(user_name):
72 cli.log.error('Keymap names must contain only {fg_cyan}a-z{fg_reset}, {fg_cyan}0-9{fg_reset} and {fg_cyan}_{fg_reset}! Please choose a different name.')
73 return False
74
63 if keymap_path_new.exists(): 75 if keymap_path_new.exists():
64 cli.log.error(f'Keymap {{fg_cyan}}{user_name}{{fg_reset}} already exists! Please choose a different name.') 76 cli.log.error(f'Keymap {{fg_cyan}}{user_name}{{fg_reset}} already exists! Please choose a different name.')
65 return False 77 return False