docs.py 768 B

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