浏览代码

Merge remote-tracking branch 'upstream/master' into develop

Nick Brassel 3 年之前
父节点
当前提交
92e9bbd9b9
共有 4 个文件被更改,包括 117 次插入4 次删除
  1. 62 0
      docs/cli_commands.md
  2. 1 0
      lib/python/qmk/cli/__init__.py
  3. 46 0
      lib/python/qmk/cli/cd.py
  4. 8 4
      lib/python/qmk/info.py

+ 62 - 0
docs/cli_commands.md

@@ -118,6 +118,68 @@ This command lets you configure the behavior of QMK. For the full `qmk config` d
 qmk config [-ro] [config_token1] [config_token2] [...] [config_tokenN]
 qmk config [-ro] [config_token1] [config_token2] [...] [config_tokenN]
 ```
 ```
 
 
+## `qmk cd`
+
+This command opens a new shell in your `qmk_firmware` directory.
+
+Note that if you are already somewhere within `QMK_HOME` (for example, the `keyboards/` folder), nothing will happen.
+
+To exit out into the parent shell, simply type `exit`.
+
+**Usage**:
+
+```
+qmk cd
+```
+
+## `qmk console`
+
+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`.
+
+**Usage**:
+
+```
+qmk console [-d <pid>:<vid>[:<index>]] [-l] [-n] [-t] [-w <seconds>]
+```
+
+**Examples**:
+
+Connect to all available keyboards and show their console messages:
+
+```
+qmk console
+```
+
+List all devices:
+
+```
+qmk console -l
+```
+
+Show only messages from clueboard/66/rev3 keyboards:
+
+```
+qmk console -d C1ED:2370
+```
+
+Show only messages from the second clueboard/66/rev3:
+
+```
+qmk console -d C1ED:2370:2
+```
+
+Show timestamps and VID:PID instead of names:
+
+```
+qmk console -n -t
+```
+
+Disable bootloader messages:
+
+```
+qmk console --no-bootloaders
+```
+
 ## `qmk doctor`
 ## `qmk doctor`
 
 
 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.
 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.

+ 1 - 0
lib/python/qmk/cli/__init__.py

@@ -31,6 +31,7 @@ safe_commands = [
 subcommands = [
 subcommands = [
     'qmk.cli.bux',
     'qmk.cli.bux',
     'qmk.cli.c2json',
     'qmk.cli.c2json',
+    'qmk.cli.cd',
     'qmk.cli.cformat',
     'qmk.cli.cformat',
     'qmk.cli.chibios.confmigrate',
     'qmk.cli.chibios.confmigrate',
     'qmk.cli.clean',
     'qmk.cli.clean',

+ 46 - 0
lib/python/qmk/cli/cd.py

@@ -0,0 +1,46 @@
+"""Open a shell in the QMK Home directory
+"""
+import sys
+import os
+
+from milc import cli
+
+from qmk.path import under_qmk_firmware
+
+
+@cli.subcommand('Go to QMK Home')
+def cd(cli):
+    """Go to QMK Home
+    """
+    if not sys.stdout.isatty():
+        cli.log.error("This command is for interactive usage only. For non-interactive usage, 'cd $(qmk env QMK_HOME)' is more robust.")
+        sys.exit(1)
+
+    if not under_qmk_firmware():
+        # Only do anything if the user is not under qmk_firmware already
+        # in order to reduce the possibility of starting multiple shells
+        cli.log.info("Spawning a subshell in your QMK_HOME directory.")
+        cli.log.info("Type 'exit' to get back to the parent shell.")
+        if not cli.platform.lower().startswith('windows'):
+            # For Linux/Mac/etc
+            # Check the user's login shell from 'passwd'
+            # alternatively fall back to $SHELL env var
+            # and finally to '/bin/bash'.
+            import getpass
+            import pwd
+            shell = pwd.getpwnam(getpass.getuser()).pw_shell
+            if not shell:
+                shell = os.environ.get('SHELL', '/bin/bash')
+            # Start the new subshell
+            os.execl(shell, shell)
+        else:
+            # For Windows
+            # Check the $SHELL env var
+            # and fall back to '/usr/bin/bash'.
+            qmk_env = os.environ.copy()
+            # Set the prompt for the new shell
+            qmk_env['MSYS2_PS1'] = qmk_env['PS1']
+            # Start the new subshell
+            cli.run([os.environ.get('SHELL', '/usr/bin/bash')], env=qmk_env)
+    else:
+        cli.log.info("Already within qmk_firmware directory.")

+ 8 - 4
lib/python/qmk/info.py

@@ -25,6 +25,13 @@ def _valid_community_layout(layout):
     return (Path('layouts/default') / layout).exists()
     return (Path('layouts/default') / layout).exists()
 
 
 
 
+def _remove_newlines_from_labels(layouts):
+    for layout_name, layout_json in layouts.items():
+        for key in layout_json['layout']:
+            if '\n' in key['label']:
+                key['label'] = key['label'].split('\n')[0]
+
+
 def info_json(keyboard):
 def info_json(keyboard):
     """Generate the info.json data for a specific keyboard.
     """Generate the info.json data for a specific keyboard.
     """
     """
@@ -100,10 +107,7 @@ def info_json(keyboard):
     _check_matrix(info_data)
     _check_matrix(info_data)
 
 
     # Remove newline characters from layout labels
     # Remove newline characters from layout labels
-    for layout_name, layout_json in layouts.items():
-        for key in layout_json['layout']:
-            if '\n' in key['label']:
-                key['label'] = key['label'].split('\n')[0]
+    _remove_newlines_from_labels(layouts)
 
 
     return info_data
     return info_data