Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI command to serve docs locally #6956

Merged
merged 6 commits into from
Oct 8, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 8080.
fauxpark marked this conversation as resolved.
Show resolved Hide resolved

**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()