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.

529 lines
13 KiB

New CLI subcommand to create clang-compatible compilation database (`compile_commands.json`) (#14370) * pulled source from dev branch * missed a file from origin * formatting * revised argument names. relaxed matching rules to work for avr too * add docstrings * added docs. tightened up regex * remove unused imports * cleaning up command file. use existing qmk dir constant * rename parser library file * move lib functions into command file. there are only 2 and they aren't large * currently debugging... * more robustly find config * updated docs * remove unused imports * reuse make executable from the main make command * pulled source from dev branch * missed a file from origin * formatting * revised argument names. relaxed matching rules to work for avr too * add docstrings * added docs. tightened up regex * remove unused imports * cleaning up command file. use existing qmk dir constant * rename parser library file * move lib functions into command file. there are only 2 and they aren't large * currently debugging... * more robustly find config * updated docs * remove unused imports * reuse make executable from the main make command * remove MAKEFLAGS from environment for better control over process management * Update .gitignore Co-authored-by: Michael Forster <forster@google.com> * add a usage line to docs * doc change as suggested Co-authored-by: Nick Brassel <nick@tzarc.org> * rename command * remove debug print statements * generate-compilation-database: fix arg handling * generate-comilation-db: improve error handling * use cli.run() instead of Popen() Co-authored-by: Xton <cdewan@apple.com> Co-authored-by: Christon DeWan <cmdpix@mac.com> Co-authored-by: Michael Forster <forster@google.com> Co-authored-by: Nick Brassel <nick@tzarc.org>
2 years ago
  1. # QMK CLI Commands
  2. # User Commands
  3. ## `qmk compile`
  4. This command allows you to compile firmware from any directory. You can compile JSON exports from <https://config.qmk.fm>, compile keymaps in the repo, or compile the keyboard in the current working directory.
  5. This command is directory aware. It will automatically fill in KEYBOARD and/or KEYMAP if you are in a keyboard or keymap directory.
  6. **Usage for Configurator Exports**:
  7. ```
  8. qmk compile [-c] <configuratorExport.json>
  9. ```
  10. **Usage for Keymaps**:
  11. ```
  12. qmk compile [-c] [-e <var>=<value>] [-j <num_jobs>] -kb <keyboard_name> -km <keymap_name>
  13. ```
  14. **Usage in Keyboard Directory**:
  15. Must be in keyboard directory with a default keymap, or in keymap directory for keyboard, or supply one with `--keymap <keymap_name>`
  16. ```
  17. qmk compile
  18. ```
  19. **Usage for building all keyboards that support a specific keymap**:
  20. ```
  21. qmk compile -kb all -km <keymap_name>
  22. ```
  23. **Example**:
  24. ```
  25. $ qmk config compile.keymap=default
  26. $ cd ~/qmk_firmware/keyboards/planck/rev6
  27. $ qmk compile
  28. Ψ Compiling keymap with make planck/rev6:default
  29. ...
  30. ```
  31. or with optional keymap argument
  32. ```
  33. $ cd ~/qmk_firmware/keyboards/clueboard/66/rev4
  34. $ qmk compile -km 66_iso
  35. Ψ Compiling keymap with make clueboard/66/rev4:66_iso
  36. ...
  37. ```
  38. or in keymap directory
  39. ```
  40. $ cd ~/qmk_firmware/keyboards/gh60/satan/keymaps/colemak
  41. $ qmk compile
  42. Ψ Compiling keymap with make gh60/satan:colemak
  43. ...
  44. ```
  45. **Usage in Layout Directory**:
  46. Must be under `qmk_firmware/layouts/`, and in a keymap folder.
  47. ```
  48. qmk compile -kb <keyboard_name>
  49. ```
  50. **Example**:
  51. ```
  52. $ cd ~/qmk_firmware/layouts/community/60_ansi/mechmerlin-ansi
  53. $ qmk compile -kb dz60
  54. Ψ Compiling keymap with make dz60:mechmerlin-ansi
  55. ...
  56. ```
  57. **Parallel Compilation**:
  58. It is possible to speed up compilation by adding the `-j`/`--parallel` flag.
  59. ```
  60. qmk compile -j <num_jobs> -kb <keyboard_name>
  61. ```
  62. The `num_jobs` argument determines the maximum number of jobs that can be used. Setting it to zero will enable parallel compilation without limiting the maximum number of jobs.
  63. ```
  64. qmk compile -j 0 -kb <keyboard_name>
  65. ```
  66. ## `qmk flash`
  67. This command is similar to `qmk compile`, but can also target a bootloader. The bootloader is optional, and is set to `:flash` by default. To specify a different bootloader, use `-bl <bootloader>`. Visit the [Flashing Firmware](flashing.md) guide for more details of the available bootloaders.
  68. This command is directory aware. It will automatically fill in KEYBOARD and/or KEYMAP if you are in a keyboard or keymap directory.
  69. **Usage for Configurator Exports**:
  70. ```
  71. qmk flash [-bl <bootloader>] [-c] [-e <var>=<value>] [-j <num_jobs>] <configuratorExport.json>
  72. ```
  73. **Usage for Keymaps**:
  74. ```
  75. qmk flash -kb <keyboard_name> -km <keymap_name> [-bl <bootloader>] [-c] [-e <var>=<value>] [-j <num_jobs>]
  76. ```
  77. **Listing the Bootloaders**
  78. ```
  79. qmk flash -b
  80. ```
  81. ## `qmk config`
  82. This command lets you configure the behavior of QMK. For the full `qmk config` documentation see [CLI Configuration](cli_configuration.md).
  83. **Usage**:
  84. ```
  85. qmk config [-ro] [config_token1] [config_token2] [...] [config_tokenN]
  86. ```
  87. ## `qmk cd`
  88. This command opens a new shell in your `qmk_firmware` directory.
  89. Note that if you are already somewhere within `QMK_HOME` (for example, the `keyboards/` folder), nothing will happen.
  90. To exit out into the parent shell, simply type `exit`.
  91. **Usage**:
  92. ```
  93. qmk cd
  94. ```
  95. ## `qmk console`
  96. This command lets you connect to keyboard consoles to get debugging messages. It only works if your keyboard firmware has been compiled with `CONSOLE_ENABLE=yes`.
  97. **Usage**:
  98. ```
  99. qmk console [-d <pid>:<vid>[:<index>]] [-l] [-n] [-t] [-w <seconds>]
  100. ```
  101. **Examples**:
  102. Connect to all available keyboards and show their console messages:
  103. ```
  104. qmk console
  105. ```
  106. List all devices:
  107. ```
  108. qmk console -l
  109. ```
  110. Show only messages from clueboard/66/rev3 keyboards:
  111. ```
  112. qmk console -d C1ED:2370
  113. ```
  114. Show only messages from the second clueboard/66/rev3:
  115. ```
  116. qmk console -d C1ED:2370:2
  117. ```
  118. Show timestamps and VID:PID instead of names:
  119. ```
  120. qmk console -n -t
  121. ```
  122. Disable bootloader messages:
  123. ```
  124. qmk console --no-bootloaders
  125. ```
  126. ## `qmk doctor`
  127. This command examines your environment and alerts you to potential build or flash problems. It can fix many of them if you want it to.
  128. **Usage**:
  129. ```
  130. qmk doctor [-y] [-n]
  131. ```
  132. **Examples**:
  133. Check your environment for problems and prompt to fix them:
  134. qmk doctor
  135. Check your environment and automatically fix any problems found:
  136. qmk doctor -y
  137. Check your environment and report problems only:
  138. qmk doctor -n
  139. ## `qmk format-json`
  140. Formats a JSON file in a (mostly) human-friendly way. Will usually correctly detect the format of the JSON (info.json or keymap.json) but you can override this with `--format` if neccesary.
  141. **Usage**:
  142. ```
  143. qmk format-json [-f FORMAT] <json_file>
  144. ```
  145. ## `qmk info`
  146. Displays information about keyboards and keymaps in QMK. You can use this to get information about a keyboard, show the layouts, display the underlying key matrix, or to pretty-print JSON keymaps.
  147. **Usage**:
  148. ```
  149. qmk info [-f FORMAT] [-m] [-l] [-km KEYMAP] [-kb KEYBOARD]
  150. ```
  151. This command is directory aware. It will automatically fill in KEYBOARD and/or KEYMAP if you are in a keyboard or keymap directory.
  152. **Examples**:
  153. Show basic information for a keyboard:
  154. qmk info -kb planck/rev5
  155. Show the matrix for a keyboard:
  156. qmk info -kb ergodox_ez -m
  157. Show a JSON keymap for a keyboard:
  158. qmk info -kb clueboard/california -km default
  159. ## `qmk json2c`
  160. Creates a keymap.c from a QMK Configurator export.
  161. **Usage**:
  162. ```
  163. qmk json2c [-o OUTPUT] filename
  164. ```
  165. ## `qmk c2json`
  166. Creates a keymap.json from a keymap.c.
  167. **Note:** Parsing C source files is not easy, therefore this subcommand may not work with your keymap. In some cases not using the C pre-processor helps.
  168. **Usage**:
  169. ```
  170. qmk c2json -km KEYMAP -kb KEYBOARD [-q] [--no-cpp] [-o OUTPUT] filename
  171. ```
  172. ## `qmk lint`
  173. Checks over a keyboard and/or keymap and highlights common errors, problems, and anti-patterns.
  174. **Usage**:
  175. ```
  176. qmk lint [-km KEYMAP] [-kb KEYBOARD] [--strict]
  177. ```
  178. This command is directory aware. It will automatically fill in KEYBOARD and/or KEYMAP if you are in a keyboard or keymap directory.
  179. **Examples**:
  180. Do a basic lint check:
  181. qmk lint -kb rominronin/katana60/rev2
  182. ## `qmk list-keyboards`
  183. This command lists all the keyboards currently defined in `qmk_firmware`
  184. **Usage**:
  185. ```
  186. qmk list-keyboards
  187. ```
  188. ## `qmk list-keymaps`
  189. This command lists all the keymaps for a specified keyboard (and revision).
  190. This command is directory aware. It will automatically fill in KEYBOARD if you are in a keyboard directory.
  191. **Usage**:
  192. ```
  193. qmk list-keymaps -kb planck/ez
  194. ```
  195. ## `qmk new-keyboard`
  196. This command creates a new keyboard based on available templates.
  197. Any arguments that are not provided will prompt for input. If `-u` is not passed and `user.name` is set in .gitconfig, it will be used as the default username in the prompt.
  198. **Usage**:
  199. ```
  200. qmk new-keyboard [-kb KEYBOARD] [-t {atmega32u4,STM32F303,etc}] [-l {60_ansi,75_iso,etc}] -u USERNAME
  201. ```
  202. ## `qmk new-keymap`
  203. This command creates a new keymap based on a keyboard's existing default keymap.
  204. This command is directory aware. It will automatically fill in KEYBOARD and/or KEYMAP if you are in a keyboard or keymap directory.
  205. **Usage**:
  206. ```
  207. qmk new-keymap [-kb KEYBOARD] [-km KEYMAP]
  208. ```
  209. ## `qmk clean`
  210. This command cleans up the `.build` folder. If `--all` is passed, any .hex or .bin files present in the `qmk_firmware` directory will also be deleted.
  211. **Usage**:
  212. ```
  213. qmk clean [-a]
  214. ```
  215. ## `qmk via2json`
  216. This command an generate a keymap.json from a VIA keymap backup. Both the layers and the macros are converted, enabling users to easily move away from a VIA-enabled firmware without writing any code or reimplementing their keymaps in QMK Configurator.
  217. **Usage**:
  218. ```
  219. qmk via2json -kb KEYBOARD [-l LAYOUT] [-km KEYMAP] [-o OUTPUT] filename
  220. ```
  221. **Example:**
  222. ```
  223. $ qmk via2json -kb ai03/polaris -o polaris_keymap.json polaris_via_backup.json
  224. Ψ Wrote keymap to /home/you/qmk_firmware/polaris_keymap.json
  225. ```
  226. ---
  227. # Developer Commands
  228. ## `qmk format-text`
  229. This command formats text files to have proper line endings.
  230. Every text file in the repository needs to have Unix (LF) line ending.
  231. If you are working on **Windows**, you must ensure that line endings are corrected in order to get your PRs merged.
  232. ```
  233. qmk format-text
  234. ```
  235. ## `qmk format-c`
  236. This command formats C code using clang-format.
  237. Run it with no arguments to format all core code that has been changed. Default checks `origin/master` with `git diff`, branch can be changed using `-b <branch_name>`
  238. Run it with `-a` to format all core code, or pass filenames on the command line to run it on specific files.
  239. **Usage for specified files**:
  240. ```
  241. qmk format-c [file1] [file2] [...] [fileN]
  242. ```
  243. **Usage for all core files**:
  244. ```
  245. qmk format-c -a
  246. ```
  247. **Usage for only changed files against origin/master**:
  248. ```
  249. qmk format-c
  250. ```
  251. **Usage for only changed files against branch_name**:
  252. ```
  253. qmk format-c -b branch_name
  254. ```
  255. ## `qmk generate-compilation-database`
  256. **Usage**:
  257. ```
  258. qmk generate-compilation-database [-kb KEYBOARD] [-km KEYMAP]
  259. ```
  260. Creates a `compile_commands.json` file.
  261. Does your IDE/editor use a language server but doesn't _quite_ find all the necessary include files? Do you hate red squigglies? Do you wish your editor could figure out `#include QMK_KEYBOARD_H`? You might need a [compilation database](https://clang.llvm.org/docs/JSONCompilationDatabase.html)! The qmk tool can build this for you.
  262. This command needs to know which keyboard and keymap to build. It uses the same configuration options as the `qmk compile` command: arguments, current directory, and config files.
  263. **Example:**
  264. ```
  265. $ cd ~/qmk_firmware/keyboards/gh60/satan/keymaps/colemak
  266. $ qmk generate-compilation-database
  267. Ψ Making clean
  268. Ψ Gathering build instructions from make -n gh60/satan:colemak
  269. Ψ Found 50 compile commands
  270. Ψ Writing build database to /Users/you/src/qmk_firmware/compile_commands.json
  271. ```
  272. Now open your dev environment and live a squiggly-free life.
  273. ## `qmk docs`
  274. This command starts a local HTTP server which you can use for browsing or improving the docs. Default port is 8936.
  275. Use the `-b`/`--browser` flag to automatically open the local webserver in your default browser.
  276. This command runs `docsify serve` if `docsify-cli` is installed (which provides live reload), otherwise Python's builtin HTTP server module will be used.
  277. **Usage**:
  278. ```
  279. qmk docs [-b] [-p PORT]
  280. ```
  281. ## `qmk generate-docs`
  282. This command allows you to generate QMK documentation locally. It can be uses for general browsing or improving the docs. External tools such as [serve](https://www.npmjs.com/package/serve) can be used to browse the generated files.
  283. **Usage**:
  284. ```
  285. qmk generate-docs
  286. ```
  287. ## `qmk generate-rgb-breathe-table`
  288. This command generates a lookup table (LUT) header file for the [RGB Lighting](feature_rgblight.md) feature's breathing animation. Place this file in your keyboard or keymap directory as `rgblight_breathe_table.h` to override the default LUT in `quantum/rgblight/`.
  289. **Usage**:
  290. ```
  291. qmk generate-rgb-breathe-table [-q] [-o OUTPUT] [-m MAX] [-c CENTER]
  292. ```
  293. ## `qmk kle2json`
  294. This command allows you to convert from raw KLE data to QMK Configurator JSON. It accepts either an absolute file path, or a file name in the current directory. By default it will not overwrite `info.json` if it is already present. Use the `-f` or `--force` flag to overwrite.
  295. **Usage**:
  296. ```
  297. qmk kle2json [-f] <filename>
  298. ```
  299. **Examples**:
  300. ```
  301. $ qmk kle2json kle.txt
  302. ☒ File info.json already exists, use -f or --force to overwrite.
  303. ```
  304. ```
  305. $ qmk kle2json -f kle.txt -f
  306. Ψ Wrote out to info.json
  307. ```
  308. ## `qmk format-python`
  309. This command formats python code in `qmk_firmware`.
  310. **Usage**:
  311. ```
  312. qmk format-python
  313. ```
  314. ## `qmk pytest`
  315. This command runs the python test suite. If you make changes to python code you should ensure this runs successfully.
  316. **Usage**:
  317. ```
  318. qmk pytest [-t TEST]
  319. ```
  320. **Examples**:
  321. Run entire test suite:
  322. qmk pytest
  323. Run test group:
  324. qmk pytest -t qmk.tests.test_cli_commands
  325. Run single test:
  326. qmk pytest -t qmk.tests.test_cli_commands.test_c2json
  327. qmk pytest -t qmk.tests.test_qmk_path
  328. ## `qmk painter-convert-graphics`
  329. This command converts images to a format usable by QMK, i.e. the QGF File Format. See the [Quantum Painter](quantum_painter.md?id=quantum-painter-cli) documentation for more information on this command.
  330. ## `qmk painter-make-font-image`
  331. This command converts a TTF font to an intermediate format for editing, before converting to the QFF File Format. See the [Quantum Painter](quantum_painter.md?id=quantum-painter-cli) documentation for more information on this command.
  332. ## `qmk painter-convert-font-image`
  333. This command converts an intermediate font image to the QFF File Format. See the [Quantum Painter](quantum_painter.md?id=quantum-painter-cli) documentation for more information on this command.