diff options
Diffstat (limited to 'lib/python/qmk/cli/flash.py')
| -rw-r--r-- | lib/python/qmk/cli/flash.py | 34 |
1 files changed, 13 insertions, 21 deletions
diff --git a/lib/python/qmk/cli/flash.py b/lib/python/qmk/cli/flash.py index cc1e6235a..f669c3cb7 100644 --- a/lib/python/qmk/cli/flash.py +++ b/lib/python/qmk/cli/flash.py | |||
| @@ -8,7 +8,7 @@ from argparse import FileType | |||
| 8 | 8 | ||
| 9 | import qmk.path | 9 | import qmk.path |
| 10 | from milc import cli | 10 | from milc import cli |
| 11 | from qmk.commands import compile_configurator_json, create_make_command, parse_configurator_json | 11 | from qmk.commands import compile_configurator_json, create_make_command, find_keyboard_keymap, parse_configurator_json |
| 12 | 12 | ||
| 13 | 13 | ||
| 14 | def print_bootloader_help(): | 14 | def print_bootloader_help(): |
| @@ -45,39 +45,31 @@ def flash(cli): | |||
| 45 | If bootloader is omitted, the one according to the rules.mk will be used. | 45 | If bootloader is omitted, the one according to the rules.mk will be used. |
| 46 | 46 | ||
| 47 | """ | 47 | """ |
| 48 | command = [] | ||
| 49 | if cli.args.bootloaders: | 48 | if cli.args.bootloaders: |
| 50 | # Provide usage and list bootloaders | 49 | # Provide usage and list bootloaders |
| 51 | cli.echo('usage: qmk flash [-h] [-b] [-kb KEYBOARD] [-km KEYMAP] [-bl BOOTLOADER] [filename]') | 50 | cli.echo('usage: qmk flash [-h] [-b] [-kb KEYBOARD] [-km KEYMAP] [-bl BOOTLOADER] [filename]') |
| 52 | print_bootloader_help() | 51 | print_bootloader_help() |
| 53 | return False | 52 | return False |
| 54 | 53 | ||
| 55 | elif cli.config.flash.keymap and not cli.config.flash.keyboard: | 54 | if cli.args.filename: |
| 56 | # If only a keymap was given but no keyboard, suggest listing keyboards | 55 | # Handle compiling a configurator JSON |
| 57 | cli.echo('usage: qmk flash [-h] [-b] [-kb KEYBOARD] [-km KEYMAP] [-bl BOOTLOADER] [filename]') | ||
| 58 | cli.log.error('run \'qmk list_keyboards\' to find out the supported keyboards') | ||
| 59 | return False | ||
| 60 | |||
| 61 | elif cli.args.filename: | ||
| 62 | # Get keymap path to log info | ||
| 63 | user_keymap = parse_configurator_json(cli.args.filename) | 56 | user_keymap = parse_configurator_json(cli.args.filename) |
| 64 | keymap_path = qmk.path.keymap(user_keymap['keyboard']) | 57 | keymap_path = qmk.path.keymap(user_keymap['keyboard']) |
| 65 | |||
| 66 | cli.log.info('Creating {fg_cyan}%s{style_reset_all} keymap in {fg_cyan}%s', user_keymap['keymap'], keymap_path) | ||
| 67 | |||
| 68 | # Convert the JSON into a C file and write it to disk. | ||
| 69 | command = compile_configurator_json(user_keymap, cli.args.bootloader) | 58 | command = compile_configurator_json(user_keymap, cli.args.bootloader) |
| 70 | 59 | ||
| 71 | cli.log.info('Wrote keymap to {fg_cyan}%s/%s/keymap.c', keymap_path, user_keymap['keymap']) | 60 | cli.log.info('Wrote keymap to {fg_cyan}%s/%s/keymap.c', keymap_path, user_keymap['keymap']) |
| 72 | 61 | ||
| 73 | elif cli.config.flash.keyboard and cli.config.flash.keymap: | ||
| 74 | # Generate the make command for a specific keyboard/keymap. | ||
| 75 | command = create_make_command(cli.config.flash.keyboard, cli.config.flash.keymap, cli.args.bootloader) | ||
| 76 | |||
| 77 | else: | 62 | else: |
| 78 | cli.echo('usage: qmk flash [-h] [-b] [-kb KEYBOARD] [-km KEYMAP] [-bl BOOTLOADER] [filename]') | 63 | # Perform the action the user specified |
| 79 | cli.log.error('You must supply a configurator export or both `--keyboard` and `--keymap`. You can also specify a bootloader with --bootloader. Use --bootloaders to list the available bootloaders.') | 64 | user_keyboard, user_keymap = find_keyboard_keymap() |
| 80 | return False | 65 | if user_keyboard and user_keymap: |
| 66 | # Generate the make command for a specific keyboard/keymap. | ||
| 67 | command = create_make_command(user_keyboard, user_keymap, cli.args.bootloader) | ||
| 68 | |||
| 69 | else: | ||
| 70 | cli.log.error('You must supply a configurator export or both `--keyboard` and `--keymap`.') | ||
| 71 | cli.echo('usage: qmk flash [-h] [-b] [-kb KEYBOARD] [-km KEYMAP] [-bl BOOTLOADER] [filename]') | ||
| 72 | return False | ||
| 81 | 73 | ||
| 82 | cli.log.info('Flashing keymap with {fg_cyan}%s\n\n', ' '.join(command)) | 74 | cli.log.info('Flashing keymap with {fg_cyan}%s\n\n', ' '.join(command)) |
| 83 | subprocess.run(command) | 75 | subprocess.run(command) |
