docs.py 871 B

123456789101112131415161718192021222324252627
  1. """Serve QMK documentation locally
  2. """
  3. import http.server
  4. from milc import cli
  5. class DocsHandler(http.server.SimpleHTTPRequestHandler):
  6. def __init__(self, *args, **kwargs):
  7. super().__init__(*args, directory='docs', **kwargs)
  8. @cli.argument('-p', '--port', default=8936, type=int, help='Port number to use.')
  9. @cli.subcommand('Run a local webserver for QMK documentation.')
  10. def docs(cli):
  11. """Spin up a local HTTPServer instance for the QMK docs.
  12. """
  13. with http.server.HTTPServer(('', cli.config.docs.port), DocsHandler) as httpd:
  14. cli.log.info("Serving QMK docs at http://localhost:%d/", cli.config.docs.port)
  15. cli.log.info("Press Control+C to exit.")
  16. try:
  17. httpd.serve_forever()
  18. except KeyboardInterrupt:
  19. cli.log.info("Stopping HTTP server...")
  20. finally:
  21. httpd.shutdown()