Skip to content

Commit

Permalink
[Docs] CLI command to serve docs locally (qmk#6956)
Browse files Browse the repository at this point in the history
* CLI command to serve docs locally

* Document it

* Default port

* Use `with` and subclass `SimpleHTTPRequestHandler` to set working dir

* Apply suggestions from code review

Co-Authored-By: skullydazed <[email protected]>

* Update docs/cli.md
  • Loading branch information
fauxpark authored and drashna committed Oct 8, 2019
1 parent e7d9570 commit 2707652
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
10 changes: 10 additions & 0 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@ This command lets you configure the behavior of QMK. For the full `qmk config` d
qmk config [-ro] [config_token1] [config_token2] [...] [config_tokenN]
```

## `qmk docs`

This command starts a local HTTP server which you can use for browsing or improving the docs. Default port is 8936.

**Usage**:

```
qmk docs [-p PORT]
```

## `qmk doctor`

This command examines your environment and alerts you to potential build or flash problems.
Expand Down
1 change: 1 addition & 0 deletions lib/python/qmk/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from . import cformat
from . import compile
from . import config
from . import docs
from . import doctor
from . import hello
from . import json
Expand Down
22 changes: 22 additions & 0 deletions lib/python/qmk/cli/docs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""Serve QMK documentation locally
"""
import http.server

from milc import cli


class DocsHandler(http.server.SimpleHTTPRequestHandler):
def __init__(self, *args, **kwargs):
super().__init__(*args, directory='docs', **kwargs)


@cli.argument('-p', '--port', default=8936, type=int, help='Port number to use.')
@cli.subcommand('Run a local webserver for QMK documentation.')
def docs(cli):
"""Spin up a local HTTPServer instance for the QMK docs.
"""
with http.server.HTTPServer(('', cli.config.docs.port), DocsHandler) as httpd:
cli.log.info("Serving QMK docs at http://localhost:%d/", cli.config.docs.port)
cli.log.info("Press Control+C to exit.")

httpd.serve_forever()

0 comments on commit 2707652

Please sign in to comment.