diff options
Diffstat (limited to 'lib/python/qmk/cli/new/keymap.py')
| -rwxr-xr-x | lib/python/qmk/cli/new/keymap.py | 12 |
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 | """ |
| 3 | import re | ||
| 3 | import shutil | 4 | import shutil |
| 4 | 5 | ||
| 5 | from milc import cli | 6 | from milc import cli |
| @@ -13,6 +14,13 @@ from qmk.keyboard import keyboard_completer, keyboard_folder | |||
| 13 | from qmk.userspace import UserspaceDefs | 14 | from qmk.userspace import UserspaceDefs |
| 14 | 15 | ||
| 15 | 16 | ||
| 17 | def 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 | |||
| 16 | def prompt_keyboard(): | 24 | def prompt_keyboard(): |
| 17 | prompt = """{fg_yellow}Select Keyboard{style_reset_all} | 25 | prompt = """{fg_yellow}Select Keyboard{style_reset_all} |
| 18 | If you`re unsure you can view a full list of supported keyboards with {fg_yellow}qmk list-keyboards{style_reset_all}. | 26 | If 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 |
