qmk 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/bin/env python3
  2. """CLI wrapper for running QMK commands.
  3. """
  4. import os
  5. import sys
  6. from pathlib import Path
  7. # Add the QMK python libs to our path
  8. script_dir = Path(os.path.realpath(__file__)).parent
  9. qmk_dir = script_dir.parent
  10. python_lib_dir = Path(qmk_dir / 'lib' / 'python').resolve()
  11. sys.path.append(str(python_lib_dir))
  12. # Setup the CLI
  13. import milc # noqa
  14. milc.EMOJI_LOGLEVELS['INFO'] = '{fg_blue}Ψ{style_reset_all}'
  15. @milc.cli.entrypoint('QMK Helper Script')
  16. def qmk_main(cli):
  17. """The function that gets run when no subcommand is provided.
  18. """
  19. cli.print_help()
  20. def main():
  21. """Setup our environment and then call the CLI entrypoint.
  22. """
  23. # Change to the root of our checkout
  24. os.environ['ORIG_CWD'] = os.getcwd()
  25. os.environ['DEPRECATED_BIN_QMK'] = '1'
  26. os.chdir(qmk_dir)
  27. print('Warning: The bin/qmk script is being deprecated. Please install the QMK CLI: python3 -m pip install qmk', file=sys.stderr)
  28. # Import the subcommands
  29. import milc.subcommand.config # noqa
  30. import qmk.cli # noqa
  31. # Execute
  32. return_code = milc.cli()
  33. if return_code is False:
  34. exit(1)
  35. elif return_code is not True and isinstance(return_code, int):
  36. if return_code < 0 or return_code > 255:
  37. milc.cli.log.error('Invalid return_code: %d', return_code)
  38. exit(255)
  39. exit(return_code)
  40. exit(0)
  41. if __name__ == '__main__':
  42. main()