You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
2.7 KiB

Configuration system for CLI (#6708) * Rework how bin/qmk handles subcommands * qmk config wip * Code to show all configs * Fully working `qmk config` command * Mark some CLI arguments so they don't pollute the config file * Fleshed out config support, nicer subcommand support * sync with installable cli * pyformat * Add a test for subcommand_modules * Documentation for the `qmk config` command * split config_token on space so qmk config is more predictable * Rework how subcommands are imported * Document `arg_only` * Document deleting from CLI * Document how multiple operations work * Add cli config to the doc index * Add tests for the cli commands * Make running the tests more reliable * Be more selective about building all default keymaps * Update new-keymap to fit the new subcommand style * Add documentation about writing CLI scripts * Document new-keyboard * Update docs/cli_configuration.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Update docs/cli_development.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Update docs/cli_development.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Update docs/cli_development.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Address yan's comments. * Apply suggestions from code review suggestions from @noahfrederick Co-Authored-By: Noah Frederick <code@noahfrederick.com> * Apply suggestions from code review Co-Authored-By: Noah Frederick <code@noahfrederick.com> * Remove pip3 from the test runner
4 years ago
Configuration system for CLI (#6708) * Rework how bin/qmk handles subcommands * qmk config wip * Code to show all configs * Fully working `qmk config` command * Mark some CLI arguments so they don't pollute the config file * Fleshed out config support, nicer subcommand support * sync with installable cli * pyformat * Add a test for subcommand_modules * Documentation for the `qmk config` command * split config_token on space so qmk config is more predictable * Rework how subcommands are imported * Document `arg_only` * Document deleting from CLI * Document how multiple operations work * Add cli config to the doc index * Add tests for the cli commands * Make running the tests more reliable * Be more selective about building all default keymaps * Update new-keymap to fit the new subcommand style * Add documentation about writing CLI scripts * Document new-keyboard * Update docs/cli_configuration.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Update docs/cli_development.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Update docs/cli_development.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Update docs/cli_development.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Address yan's comments. * Apply suggestions from code review suggestions from @noahfrederick Co-Authored-By: Noah Frederick <code@noahfrederick.com> * Apply suggestions from code review Co-Authored-By: Noah Frederick <code@noahfrederick.com> * Remove pip3 from the test runner
4 years ago
  1. """This script automates the copying of the default keymap into your own keymap.
  2. """
  3. import shutil
  4. from milc import cli
  5. from milc.questions import question
  6. from qmk.path import is_keyboard, keymap
  7. from qmk.git import git_get_username
  8. from qmk.decorators import automagic_keyboard, automagic_keymap
  9. from qmk.keyboard import keyboard_completer, keyboard_folder
  10. def prompt_keyboard():
  11. prompt = """{fg_yellow}Select Keyboard{style_reset_all}
  12. If you`re unsure you can view a full list of supported keyboards with {fg_yellow}qmk list-keyboards{style_reset_all}.
  13. Keyboard Name? """
  14. return question(prompt)
  15. def prompt_user():
  16. prompt = """
  17. {fg_yellow}Name Your Keymap{style_reset_all}
  18. Used for maintainer, copyright, etc
  19. Your GitHub Username? """
  20. return question(prompt, default=git_get_username())
  21. @cli.argument('-kb', '--keyboard', type=keyboard_folder, completer=keyboard_completer, help='Specify keyboard name. Example: 1upkeyboards/1up60hse')
  22. @cli.argument('-km', '--keymap', help='Specify the name for the new keymap directory')
  23. @cli.subcommand('Creates a new keymap for the keyboard of your choosing')
  24. @automagic_keyboard
  25. @automagic_keymap
  26. def new_keymap(cli):
  27. """Creates a new keymap for the keyboard of your choosing.
  28. """
  29. cli.log.info('{style_bright}Generating a new keymap{style_normal}')
  30. cli.echo('')
  31. # ask for user input if keyboard or keymap was not provided in the command line
  32. kb_name = cli.config.new_keymap.keyboard if cli.config.new_keymap.keyboard else prompt_keyboard()
  33. user_name = cli.config.new_keymap.keymap if cli.config.new_keymap.keymap else prompt_user()
  34. # check directories
  35. if not is_keyboard(kb_name):
  36. cli.log.error(f'Keyboard {{fg_cyan}}{kb_name}{{fg_reset}} does not exist! Please choose a valid name.')
  37. return False
  38. # generate keymap paths
  39. km_path = keymap(kb_name)
  40. keymap_path_default = km_path / 'default'
  41. keymap_path_new = km_path / user_name
  42. if not keymap_path_default.exists():
  43. cli.log.error(f'Default keymap {{fg_cyan}}{keymap_path_default}{{fg_reset}} does not exist!')
  44. return False
  45. if keymap_path_new.exists():
  46. cli.log.error(f'Keymap {{fg_cyan}}{user_name}{{fg_reset}} already exists! Please choose a different name.')
  47. return False
  48. # create user directory with default keymap files
  49. shutil.copytree(keymap_path_default, keymap_path_new, symlinks=True)
  50. # end message to user
  51. 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}}')
  52. 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}}.")