2019-07-15 19:14:27 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
"""CLI wrapper for running QMK commands.
|
|
|
|
"""
|
|
|
|
import os
|
|
|
|
import sys
|
2019-11-27 20:27:06 +00:00
|
|
|
from pathlib import Path
|
2019-07-15 19:14:27 +00:00
|
|
|
|
|
|
|
# Add the QMK python libs to our path
|
2019-11-27 20:27:06 +00:00
|
|
|
script_dir = Path(os.path.realpath(__file__)).parent
|
|
|
|
qmk_dir = script_dir.parent
|
|
|
|
python_lib_dir = Path(qmk_dir / 'lib' / 'python').resolve()
|
|
|
|
sys.path.append(str(python_lib_dir))
|
|
|
|
|
2020-03-23 16:08:35 +00:00
|
|
|
# Setup the CLI
|
|
|
|
import milc # noqa
|
|
|
|
|
2019-09-22 20:25:33 +00:00
|
|
|
milc.EMOJI_LOGLEVELS['INFO'] = '{fg_blue}Ψ{style_reset_all}'
|
2019-07-15 19:14:27 +00:00
|
|
|
|
|
|
|
|
2019-09-22 20:25:33 +00:00
|
|
|
@milc.cli.entrypoint('QMK Helper Script')
|
|
|
|
def qmk_main(cli):
|
|
|
|
"""The function that gets run when no subcommand is provided.
|
|
|
|
"""
|
|
|
|
cli.print_help()
|
2019-07-15 19:14:27 +00:00
|
|
|
|
|
|
|
|
2019-09-22 20:25:33 +00:00
|
|
|
def main():
|
|
|
|
"""Setup our environment and then call the CLI entrypoint.
|
|
|
|
"""
|
|
|
|
# Change to the root of our checkout
|
|
|
|
os.environ['ORIG_CWD'] = os.getcwd()
|
|
|
|
os.chdir(qmk_dir)
|
2019-07-15 19:14:27 +00:00
|
|
|
|
2019-09-22 20:25:33 +00:00
|
|
|
# Import the subcommands
|
2019-11-20 22:54:18 +00:00
|
|
|
import qmk.cli # noqa
|
2019-07-15 19:14:27 +00:00
|
|
|
|
2019-09-22 20:25:33 +00:00
|
|
|
# Execute
|
2019-08-22 06:40:24 +00:00
|
|
|
return_code = milc.cli()
|
2019-09-22 20:25:33 +00:00
|
|
|
|
2019-08-22 06:40:24 +00:00
|
|
|
if return_code is False:
|
|
|
|
exit(1)
|
2019-09-22 20:25:33 +00:00
|
|
|
|
|
|
|
elif return_code is not True and isinstance(return_code, int):
|
|
|
|
if return_code < 0 or return_code > 255:
|
|
|
|
milc.cli.log.error('Invalid return_code: %d', return_code)
|
|
|
|
exit(255)
|
|
|
|
|
2019-08-22 06:40:24 +00:00
|
|
|
exit(return_code)
|
2019-09-22 20:25:33 +00:00
|
|
|
|
|
|
|
exit(0)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|