Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5229ce14e3 | |||
| 8fa960f25e | |||
| 1481dfe157 | |||
| ac39b9bb0f | |||
| 44a446308f | |||
| 90bdf52416 | |||
| 191980052e | |||
| 5fbdd95c4b | |||
| 1002360e20 | |||
| a03aa1cbba | |||
| a0b692d718 | |||
| ab7d0c6e46 | |||
| 73c903b8b6 | |||
| 8f2185af32 | |||
| bae2f1f1ee | |||
| 120ce557f1 | |||
| a15b0d6460 | |||
| f0dafaf068 | |||
| 3414bdcaa3 | |||
| c8567d8098 |
@@ -1,5 +1,5 @@
|
|||||||
# QMK CLI
|
# QMK CLI
|
||||||

|
[](https://github.com/qmk/qmk_cli/actions?query=workflow%3A%22CLI+Setup%22)
|
||||||
A program to help users work with [QMK Firmware](https://qmk.fm/).
|
A program to help users work with [QMK Firmware](https://qmk.fm/).
|
||||||
|
|
||||||
# Features
|
# Features
|
||||||
|
|||||||
@@ -242,15 +242,24 @@ class SubparserWrapper(object):
|
|||||||
|
|
||||||
This also stores the default for the argument in `self.cli.default_arguments`.
|
This also stores the default for the argument in `self.cli.default_arguments`.
|
||||||
"""
|
"""
|
||||||
if 'action' in kwargs and kwargs['action'] == 'store_boolean':
|
if kwargs.get('action') == 'store_boolean':
|
||||||
# Store boolean will call us again with the enable/disable flag arguments
|
# Store boolean will call us again with the enable/disable flag arguments
|
||||||
return handle_store_boolean(self, *args, **kwargs)
|
return handle_store_boolean(self, *args, **kwargs)
|
||||||
|
|
||||||
self.cli.acquire_lock()
|
self.cli.acquire_lock()
|
||||||
|
argument_name = self.cli.get_argument_name(*args, **kwargs)
|
||||||
|
|
||||||
self.subparser.add_argument(*args, **kwargs)
|
self.subparser.add_argument(*args, **kwargs)
|
||||||
|
|
||||||
|
if kwargs.get('action') == 'store_false':
|
||||||
|
self.cli._config_store_false.append(argument_name)
|
||||||
|
|
||||||
|
if kwargs.get('action') == 'store_true':
|
||||||
|
self.cli._config_store_true.append(argument_name)
|
||||||
|
|
||||||
if self.submodule not in self.cli.default_arguments:
|
if self.submodule not in self.cli.default_arguments:
|
||||||
self.cli.default_arguments[self.submodule] = {}
|
self.cli.default_arguments[self.submodule] = {}
|
||||||
self.cli.default_arguments[self.submodule][self.cli.get_argument_name(*args, **kwargs)] = kwargs.get('default')
|
self.cli.default_arguments[self.submodule][argument_name] = kwargs.get('default')
|
||||||
self.cli.release_lock()
|
self.cli.release_lock()
|
||||||
|
|
||||||
|
|
||||||
@@ -268,11 +277,13 @@ class MILC(object):
|
|||||||
|
|
||||||
# Define some basic info
|
# Define some basic info
|
||||||
self.acquire_lock()
|
self.acquire_lock()
|
||||||
|
self._config_store_true = []
|
||||||
|
self._config_store_false = []
|
||||||
self._description = None
|
self._description = None
|
||||||
self._entrypoint = None
|
self._entrypoint = None
|
||||||
self._inside_context_manager = False
|
self._inside_context_manager = False
|
||||||
self.ansi = ansi_colors
|
self.ansi = ansi_colors
|
||||||
self.arg_only = []
|
self.arg_only = {}
|
||||||
self.config = self.config_source = None
|
self.config = self.config_source = None
|
||||||
self.config_file = None
|
self.config_file = None
|
||||||
self.default_arguments = {}
|
self.default_arguments = {}
|
||||||
@@ -377,7 +388,7 @@ class MILC(object):
|
|||||||
self.add_argument('--log-file', help='File to write log messages to')
|
self.add_argument('--log-file', help='File to write log messages to')
|
||||||
self.add_argument('--color', action='store_boolean', default=True, help='color in output')
|
self.add_argument('--color', action='store_boolean', default=True, help='color in output')
|
||||||
self.add_argument('--config-file', help='The location for the configuration file')
|
self.add_argument('--config-file', help='The location for the configuration file')
|
||||||
self.arg_only.append('config_file')
|
self.arg_only['config_file'] = ['general']
|
||||||
|
|
||||||
def add_subparsers(self, title='Sub-commands', **kwargs):
|
def add_subparsers(self, title='Sub-commands', **kwargs):
|
||||||
if self._inside_context_manager:
|
if self._inside_context_manager:
|
||||||
@@ -427,17 +438,20 @@ class MILC(object):
|
|||||||
raise RuntimeError('You must run this before the with statement!')
|
raise RuntimeError('You must run this before the with statement!')
|
||||||
|
|
||||||
def argument_function(handler):
|
def argument_function(handler):
|
||||||
if 'arg_only' in kwargs and kwargs['arg_only']:
|
subcommand_name = handler.__name__.replace("_", "-")
|
||||||
|
|
||||||
|
if kwargs.get('arg_only'):
|
||||||
arg_name = self.get_argument_name(*args, **kwargs)
|
arg_name = self.get_argument_name(*args, **kwargs)
|
||||||
self.arg_only.append(arg_name)
|
if arg_name not in self.arg_only:
|
||||||
|
self.arg_only[arg_name] = []
|
||||||
|
self.arg_only[arg_name].append(subcommand_name)
|
||||||
del kwargs['arg_only']
|
del kwargs['arg_only']
|
||||||
|
|
||||||
name = handler.__name__.replace("_", "-")
|
|
||||||
if handler is self._entrypoint:
|
if handler is self._entrypoint:
|
||||||
self.add_argument(*args, **kwargs)
|
self.add_argument(*args, **kwargs)
|
||||||
|
|
||||||
elif name in self.subcommands:
|
elif subcommand_name in self.subcommands:
|
||||||
self.subcommands[name].add_argument(*args, **kwargs)
|
self.subcommands[subcommand_name].add_argument(*args, **kwargs)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise RuntimeError('Decorated function is not entrypoint or subcommand!')
|
raise RuntimeError('Decorated function is not entrypoint or subcommand!')
|
||||||
@@ -511,35 +525,37 @@ class MILC(object):
|
|||||||
if argument in ('subparsers', 'entrypoint'):
|
if argument in ('subparsers', 'entrypoint'):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if argument not in self.arg_only:
|
# Find the argument's section
|
||||||
# Find the argument's section
|
# Underscores in command's names are converted to dashes during initialization.
|
||||||
# Underscores in command's names are converted to dashes during initialization.
|
# TODO(Erovia) Find a better solution
|
||||||
# TODO(Erovia) Find a better solution
|
entrypoint_name = self._entrypoint.__name__.replace("_", "-")
|
||||||
entrypoint_name = self._entrypoint.__name__.replace("_", "-")
|
if entrypoint_name in self.default_arguments and argument in self.default_arguments[entrypoint_name]:
|
||||||
if entrypoint_name in self.default_arguments and argument in self.default_arguments[entrypoint_name]:
|
argument_found = True
|
||||||
argument_found = True
|
section = self._entrypoint.__name__
|
||||||
section = self._entrypoint.__name__
|
if argument in self.default_arguments['general']:
|
||||||
if argument in self.default_arguments['general']:
|
argument_found = True
|
||||||
argument_found = True
|
section = 'general'
|
||||||
section = 'general'
|
|
||||||
|
|
||||||
if not argument_found:
|
if not argument_found:
|
||||||
raise RuntimeError('Could not find argument in `self.default_arguments`. This should be impossible!')
|
raise RuntimeError('Could not find argument in `self.default_arguments`. This should be impossible!')
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
|
if argument not in self.arg_only or section not in self.arg_only[argument]:
|
||||||
|
# Determine the arg value and source
|
||||||
|
arg_value = getattr(self.args, argument)
|
||||||
|
if argument in self._config_store_true and arg_value:
|
||||||
|
passed_on_cmdline = True
|
||||||
|
elif argument in self._config_store_false and not arg_value:
|
||||||
|
passed_on_cmdline = True
|
||||||
|
elif arg_value is not None:
|
||||||
|
passed_on_cmdline = True
|
||||||
|
else:
|
||||||
|
passed_on_cmdline = False
|
||||||
|
|
||||||
# Merge this argument into self.config
|
# Merge this argument into self.config
|
||||||
if argument in self.default_arguments['general'] or argument in self.default_arguments[entrypoint_name]:
|
if passed_on_cmdline and (argument in self.default_arguments['general'] or argument in self.default_arguments[entrypoint_name] or argument not in self.config[entrypoint_name]):
|
||||||
arg_value = getattr(self.args, argument)
|
self.config[section][argument] = arg_value
|
||||||
if arg_value is not None:
|
self.config_source[section][argument] = 'argument'
|
||||||
self.config[section][argument] = arg_value
|
|
||||||
self.config_source[section][argument] = 'argument'
|
|
||||||
else:
|
|
||||||
if argument not in self.config[entrypoint_name]:
|
|
||||||
# Check if the argument exist for this section
|
|
||||||
arg = getattr(self.args, argument)
|
|
||||||
if arg is not None:
|
|
||||||
self.config[section][argument] = arg
|
|
||||||
self.config_source[section][argument] = 'argument'
|
|
||||||
|
|
||||||
self.release_lock()
|
self.release_lock()
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,3 +1,3 @@
|
|||||||
"""A program to help you work with qmk_firmware."""
|
"""A program to help you work with qmk_firmware."""
|
||||||
|
|
||||||
__version__ = '0.0.29'
|
__version__ = '0.0.33'
|
||||||
|
|||||||
+13
-2
@@ -9,6 +9,7 @@ import subprocess
|
|||||||
import sys
|
import sys
|
||||||
from functools import lru_cache
|
from functools import lru_cache
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
import platform
|
||||||
|
|
||||||
import milc
|
import milc
|
||||||
|
|
||||||
@@ -30,7 +31,7 @@ def in_qmk_firmware():
|
|||||||
while len(cur_dir.parents) > 0:
|
while len(cur_dir.parents) > 0:
|
||||||
found_bin = cur_dir / 'bin' / 'qmk'
|
found_bin = cur_dir / 'bin' / 'qmk'
|
||||||
if found_bin.is_file():
|
if found_bin.is_file():
|
||||||
command = [found_bin.as_posix(), '--version']
|
command = [sys.executable, found_bin.as_posix()]
|
||||||
result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
|
|
||||||
if result.returncode == 0:
|
if result.returncode == 0:
|
||||||
@@ -69,6 +70,11 @@ def main():
|
|||||||
print('Warning: Your Python version is out of date! Some subcommands may not work!')
|
print('Warning: Your Python version is out of date! Some subcommands may not work!')
|
||||||
print('Please upgrade to Python 3.6 or later.')
|
print('Please upgrade to Python 3.6 or later.')
|
||||||
|
|
||||||
|
if 'windows' in platform.platform().lower():
|
||||||
|
if 'mingw64' not in sys.executable or 'mingw64' not in os.environ.get('MSYSTEM_PREFIX', ''):
|
||||||
|
print('Warning: It seems you are not using the MINGW64 terminal.')
|
||||||
|
print('While the MSYS one can work, too, we recommend/support you start "MSYS2 MinGW 64-bit".\n')
|
||||||
|
|
||||||
# Environment setup
|
# Environment setup
|
||||||
import qmk_cli
|
import qmk_cli
|
||||||
milc.cli.version = qmk_cli.__version__
|
milc.cli.version = qmk_cli.__version__
|
||||||
@@ -82,7 +88,12 @@ def main():
|
|||||||
if qmk_firmware.exists():
|
if qmk_firmware.exists():
|
||||||
os.chdir(str(qmk_firmware))
|
os.chdir(str(qmk_firmware))
|
||||||
sys.path.append(str(qmk_firmware / 'lib' / 'python'))
|
sys.path.append(str(qmk_firmware / 'lib' / 'python'))
|
||||||
import qmk.cli
|
try:
|
||||||
|
import qmk.cli
|
||||||
|
except ImportError:
|
||||||
|
print('Error: %s is too old or not set up correctly!' % qmk_firmware)
|
||||||
|
print('Please update it or remove it completely before continuing.')
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
# Call the entrypoint
|
# Call the entrypoint
|
||||||
milc.cli()
|
milc.cli()
|
||||||
|
|||||||
@@ -14,7 +14,8 @@ default_fork = 'qmk/' + default_repo
|
|||||||
default_branch = 'master'
|
default_branch = 'master'
|
||||||
|
|
||||||
|
|
||||||
@cli.argument('-y', '--yes', action='store_true', help='Answer yes to all questions')
|
@cli.argument('-n', '--no', arg_only=True, action='store_true', help='Answer no to all questions')
|
||||||
|
@cli.argument('-y', '--yes', arg_only=True, action='store_true', help='Answer yes to all questions')
|
||||||
@cli.argument('--baseurl', default='https://github.com', help='The URL all git operations start from')
|
@cli.argument('--baseurl', default='https://github.com', help='The URL all git operations start from')
|
||||||
@cli.argument('-b', '--branch', default=default_branch, help='The branch to clone')
|
@cli.argument('-b', '--branch', default=default_branch, help='The branch to clone')
|
||||||
@cli.argument('destination', default=os.environ['QMK_HOME'], nargs='?', help='The directory to clone to')
|
@cli.argument('destination', default=os.environ['QMK_HOME'], nargs='?', help='The directory to clone to')
|
||||||
@@ -23,8 +24,13 @@ default_branch = 'master'
|
|||||||
def setup(cli):
|
def setup(cli):
|
||||||
qmk_firmware = Path(cli.args.destination)
|
qmk_firmware = Path(cli.args.destination)
|
||||||
|
|
||||||
|
# Sanity checks
|
||||||
|
if cli.args.yes and cli.args.no:
|
||||||
|
cli.log.error("Can't use both --yes and --no at the same time.")
|
||||||
|
exit(1)
|
||||||
|
|
||||||
# Check on qmk_firmware, and if it doesn't exist offer to check it out.
|
# Check on qmk_firmware, and if it doesn't exist offer to check it out.
|
||||||
if qmk_firmware.exists():
|
if (qmk_firmware / 'Makefile').exists():
|
||||||
cli.log.info('Found qmk_firmware at %s.', str(qmk_firmware))
|
cli.log.info('Found qmk_firmware at %s.', str(qmk_firmware))
|
||||||
else:
|
else:
|
||||||
cli.log.error('qmk_firmware not found!')
|
cli.log.error('qmk_firmware not found!')
|
||||||
@@ -35,7 +41,12 @@ def setup(cli):
|
|||||||
# Run `qmk_firmware/bin/qmk doctor` to check the rest of the environment out
|
# Run `qmk_firmware/bin/qmk doctor` to check the rest of the environment out
|
||||||
if qmk_firmware.exists():
|
if qmk_firmware.exists():
|
||||||
qmk_bin = qmk_firmware / 'bin' / 'qmk'
|
qmk_bin = qmk_firmware / 'bin' / 'qmk'
|
||||||
doctor = subprocess.run([sys.executable, str(qmk_bin), 'doctor'])
|
doctor_cmd = [sys.executable, str(qmk_bin), 'doctor']
|
||||||
|
if cli.args.yes:
|
||||||
|
doctor_cmd.append('--yes')
|
||||||
|
if cli.args.no:
|
||||||
|
doctor_cmd.append('--no')
|
||||||
|
doctor = subprocess.run(doctor_cmd)
|
||||||
if doctor.returncode != 0:
|
if doctor.returncode != 0:
|
||||||
cli.log.error('Your build environment is not setup completely.')
|
cli.log.error('Your build environment is not setup completely.')
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
[bumpversion]
|
[bumpversion]
|
||||||
current_version = 0.0.29
|
current_version = 0.0.33
|
||||||
commit = True
|
commit = True
|
||||||
tag = True
|
tag = True
|
||||||
tag_name = {new_version}
|
tag_name = {new_version}
|
||||||
|
|||||||
Reference in New Issue
Block a user