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.

614 lines
15 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. This command can also flash binary firmware files (hex or bin) such as the ones produced by [Configurator](https://config.qmk.fm).
  70. **Usage for Configurator Exports**:
  71. ```
  72. qmk flash [-bl <bootloader>] [-c] [-e <var>=<value>] [-j <num_jobs>] <configuratorExport.json>
  73. ```
  74. **Usage for Keymaps**:
  75. ```
  76. qmk flash -kb <keyboard_name> -km <keymap_name> [-bl <bootloader>] [-c] [-e <var>=<value>] [-j <num_jobs>]
  77. ```
  78. **Usage for pre-compiled firmwares**:
  79. **Note**: The microcontroller needs to be specified (`-m` argument) for keyboards with the following bootloaders:
  80. * HalfKay
  81. * QMK HID
  82. * USBaspLoader
  83. ISP flashing is also supported with the following flashers and require the microcontroller to be specified:
  84. * USBasp
  85. * USBtinyISP
  86. ```
  87. qmk flash [-m <microcontroller>] <compiledFirmware.[bin|hex]>
  88. ```
  89. **Listing the Bootloaders**
  90. ```
  91. qmk flash -b
  92. ```
  93. ## `qmk config`
  94. This command lets you configure the behavior of QMK. For the full `qmk config` documentation see [CLI Configuration](cli_configuration.md).
  95. **Usage**:
  96. ```
  97. qmk config [-ro] [config_token1] [config_token2] [...] [config_tokenN]
  98. ```
  99. ## `qmk cd`
  100. This command opens a new shell in your `qmk_firmware` directory.
  101. Note that if you are already somewhere within `QMK_HOME` (for example, the `keyboards/` folder), nothing will happen.
  102. To exit out into the parent shell, simply type `exit`.
  103. **Usage**:
  104. ```
  105. qmk cd
  106. ```
  107. ## `qmk console`
  108. 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`.
  109. **Usage**:
  110. ```
  111. qmk console [-d <pid>:<vid>[:<index>]] [-l] [-n] [-t] [-w <seconds>]
  112. ```
  113. **Examples**:
  114. Connect to all available keyboards and show their console messages:
  115. ```
  116. qmk console
  117. ```
  118. List all devices:
  119. ```
  120. qmk console -l
  121. ```
  122. Show only messages from clueboard/66/rev3 keyboards:
  123. ```
  124. qmk console -d C1ED:2370
  125. ```
  126. Show only messages from the second clueboard/66/rev3:
  127. ```
  128. qmk console -d C1ED:2370:2
  129. ```
  130. Show timestamps and VID:PID instead of names:
  131. ```
  132. qmk console -n -t
  133. ```
  134. Disable bootloader messages:
  135. ```
  136. qmk console --no-bootloaders
  137. ```
  138. ## `qmk doctor`
  139. 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.
  140. **Usage**:
  141. ```
  142. qmk doctor [-y] [-n]
  143. ```
  144. **Examples**:
  145. Check your environment for problems and prompt to fix them:
  146. qmk doctor
  147. Check your environment and automatically fix any problems found:
  148. qmk doctor -y
  149. Check your environment and report problems only:
  150. qmk doctor -n
  151. ## `qmk format-json`
  152. 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.
  153. **Usage**:
  154. ```
  155. qmk format-json [-f FORMAT] <json_file>
  156. ```
  157. ## `qmk info`
  158. 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.
  159. **Usage**:
  160. ```
  161. qmk info [-f FORMAT] [-m] [-l] [-km KEYMAP] [-kb KEYBOARD]
  162. ```
  163. This command is directory aware. It will automatically fill in KEYBOARD and/or KEYMAP if you are in a keyboard or keymap directory.
  164. **Examples**:
  165. Show basic information for a keyboard:
  166. qmk info -kb planck/rev5
  167. Show the matrix for a keyboard:
  168. qmk info -kb ergodox_ez -m
  169. Show a JSON keymap for a keyboard:
  170. qmk info -kb clueboard/california -km default
  171. ## `qmk json2c`
  172. Creates a keymap.c from a QMK Configurator export.
  173. **Usage**:
  174. ```
  175. qmk json2c [-o OUTPUT] filename
  176. ```
  177. ## `qmk c2json`
  178. Creates a keymap.json from a keymap.c.
  179. **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.
  180. **Usage**:
  181. ```
  182. qmk c2json -km KEYMAP -kb KEYBOARD [-q] [--no-cpp] [-o OUTPUT] filename
  183. ```
  184. ## `qmk lint`
  185. Checks over a keyboard and/or keymap and highlights common errors, problems, and anti-patterns.
  186. **Usage**:
  187. ```
  188. qmk lint [-km KEYMAP] [-kb KEYBOARD] [--strict]
  189. ```
  190. This command is directory aware. It will automatically fill in KEYBOARD and/or KEYMAP if you are in a keyboard or keymap directory.
  191. **Examples**:
  192. Do a basic lint check:
  193. qmk lint -kb rominronin/katana60/rev2
  194. ## `qmk list-keyboards`
  195. This command lists all the keyboards currently defined in `qmk_firmware`
  196. **Usage**:
  197. ```
  198. qmk list-keyboards
  199. ```
  200. ## `qmk list-keymaps`
  201. This command lists all the keymaps for a specified keyboard (and revision).
  202. This command is directory aware. It will automatically fill in KEYBOARD if you are in a keyboard directory.
  203. **Usage**:
  204. ```
  205. qmk list-keymaps -kb planck/ez
  206. ```
  207. ## `qmk new-keyboard`
  208. This command creates a new keyboard based on available templates.
  209. 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.
  210. **Usage**:
  211. ```
  212. qmk new-keyboard [-kb KEYBOARD] [-t {atmega32u4,STM32F303,etc}] [-l {60_ansi,75_iso,etc}] -u USERNAME
  213. ```
  214. ## `qmk new-keymap`
  215. This command creates a new keymap based on a keyboard's existing default keymap.
  216. This command is directory aware. It will automatically fill in KEYBOARD and/or KEYMAP if you are in a keyboard or keymap directory.
  217. **Usage**:
  218. ```
  219. qmk new-keymap [-kb KEYBOARD] [-km KEYMAP]
  220. ```
  221. ## `qmk clean`
  222. 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.
  223. **Usage**:
  224. ```
  225. qmk clean [-a]
  226. ```
  227. ## `qmk via2json`
  228. 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.
  229. **Usage**:
  230. ```
  231. qmk via2json -kb KEYBOARD [-l LAYOUT] [-km KEYMAP] [-o OUTPUT] filename
  232. ```
  233. **Example:**
  234. ```
  235. $ qmk via2json -kb ai03/polaris -o polaris_keymap.json polaris_via_backup.json
  236. Ψ Wrote keymap to /home/you/qmk_firmware/polaris_keymap.json
  237. ```
  238. ## `qmk import-keyboard`
  239. This command imports a data-driven `info.json` keyboard into the repo.
  240. **Usage**:
  241. ```
  242. usage: qmk import-keyboard [-h] filename
  243. ```
  244. **Example:**
  245. ```
  246. $ qmk import-keyboard ~/Downloads/forever60.json
  247. Ψ Importing forever60.json.
  248. Ψ Imported a new keyboard named forever60.
  249. Ψ To start working on things, `cd` into keyboards/forever60,
  250. Ψ or open the directory in your preferred text editor.
  251. Ψ And build with qmk compile -kb forever60 -km default.
  252. ```
  253. ## `qmk import-keymap`
  254. This command imports a data-driven `keymap.json` keymap into the repo.
  255. **Usage**:
  256. ```
  257. usage: qmk import-keymap [-h] filename
  258. ```
  259. **Example:**
  260. ```
  261. qmk import-keymap ~/Downloads/asdf2.json
  262. Ψ Importing asdf2.json.
  263. Ψ Imported a new keymap named asdf2.
  264. Ψ To start working on things, `cd` into keyboards/takashicompany/dogtag/keymaps/asdf2,
  265. Ψ or open the directory in your preferred text editor.
  266. Ψ And build with qmk compile -kb takashicompany/dogtag -km asdf2.
  267. ```
  268. ## `qmk import-kbfirmware`
  269. This command creates a new keyboard based on a [Keyboard Firmware Builder](https://kbfirmware.com/) export.
  270. **Usage**:
  271. ```
  272. usage: qmk import-kbfirmware [-h] filename
  273. ```
  274. **Example:**
  275. ```
  276. $ qmk import-kbfirmware ~/Downloads/gh62.json
  277. Ψ Importing gh62.json.
  278. ⚠ Support here is basic - Consider using 'qmk new-keyboard' instead
  279. Ψ Imported a new keyboard named gh62.
  280. Ψ To start working on things, `cd` into keyboards/gh62,
  281. Ψ or open the directory in your preferred text editor.
  282. Ψ And build with qmk compile -kb gh62 -km default.
  283. ```
  284. ---
  285. # Developer Commands
  286. ## `qmk format-text`
  287. This command formats text files to have proper line endings.
  288. Every text file in the repository needs to have Unix (LF) line ending.
  289. If you are working on **Windows**, you must ensure that line endings are corrected in order to get your PRs merged.
  290. ```
  291. qmk format-text
  292. ```
  293. ## `qmk format-c`
  294. This command formats C code using clang-format.
  295. 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>`
  296. Run it with `-a` to format all core code, or pass filenames on the command line to run it on specific files.
  297. **Usage for specified files**:
  298. ```
  299. qmk format-c [file1] [file2] [...] [fileN]
  300. ```
  301. **Usage for all core files**:
  302. ```
  303. qmk format-c -a
  304. ```
  305. **Usage for only changed files against origin/master**:
  306. ```
  307. qmk format-c
  308. ```
  309. **Usage for only changed files against branch_name**:
  310. ```
  311. qmk format-c -b branch_name
  312. ```
  313. ## `qmk generate-compilation-database`
  314. **Usage**:
  315. ```
  316. qmk generate-compilation-database [-kb KEYBOARD] [-km KEYMAP]
  317. ```
  318. Creates a `compile_commands.json` file.
  319. 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.
  320. 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.
  321. **Example:**
  322. ```
  323. $ cd ~/qmk_firmware/keyboards/gh60/satan/keymaps/colemak
  324. $ qmk generate-compilation-database
  325. Ψ Making clean
  326. Ψ Gathering build instructions from make -n gh60/satan:colemak
  327. Ψ Found 50 compile commands
  328. Ψ Writing build database to /Users/you/src/qmk_firmware/compile_commands.json
  329. ```
  330. Now open your dev environment and live a squiggly-free life.
  331. ## `qmk docs`
  332. This command starts a local HTTP server which you can use for browsing or improving the docs. Default port is 8936.
  333. Use the `-b`/`--browser` flag to automatically open the local webserver in your default browser.
  334. This command runs `docsify serve` if `docsify-cli` is installed (which provides live reload), otherwise Python's builtin HTTP server module will be used.
  335. **Usage**:
  336. ```
  337. qmk docs [-b] [-p PORT]
  338. ```
  339. ## `qmk generate-docs`
  340. 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.
  341. **Usage**:
  342. ```
  343. qmk generate-docs
  344. ```
  345. ## `qmk generate-rgb-breathe-table`
  346. 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/`.
  347. **Usage**:
  348. ```
  349. qmk generate-rgb-breathe-table [-q] [-o OUTPUT] [-m MAX] [-c CENTER]
  350. ```
  351. ## `qmk kle2json`
  352. 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.
  353. **Usage**:
  354. ```
  355. qmk kle2json [-f] <filename>
  356. ```
  357. **Examples**:
  358. ```
  359. $ qmk kle2json kle.txt
  360. ☒ File info.json already exists, use -f or --force to overwrite.
  361. ```
  362. ```
  363. $ qmk kle2json -f kle.txt -f
  364. Ψ Wrote out to info.json
  365. ```
  366. ## `qmk format-python`
  367. This command formats python code in `qmk_firmware`.
  368. **Usage**:
  369. ```
  370. qmk format-python
  371. ```
  372. ## `qmk pytest`
  373. This command runs the python test suite. If you make changes to python code you should ensure this runs successfully.
  374. **Usage**:
  375. ```
  376. qmk pytest [-t TEST]
  377. ```
  378. **Examples**:
  379. Run entire test suite:
  380. qmk pytest
  381. Run test group:
  382. qmk pytest -t qmk.tests.test_cli_commands
  383. Run single test:
  384. qmk pytest -t qmk.tests.test_cli_commands.test_c2json
  385. qmk pytest -t qmk.tests.test_qmk_path
  386. ## `qmk painter-convert-graphics`
  387. 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.
  388. ## `qmk painter-make-font-image`
  389. 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.
  390. ## `qmk painter-convert-font-image`
  391. 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.