Skip to content

Commit

Permalink
Use mkdocs-click for command line documentation (#306)
Browse files Browse the repository at this point in the history
  • Loading branch information
athackst committed Apr 29, 2022
1 parent c4f102f commit 1a582ed
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 31 deletions.
1 change: 1 addition & 0 deletions mkdocs.yml
Expand Up @@ -30,6 +30,7 @@ markdown_extensions:
- pymdownx.emoji:
emoji_index: !!python/name:materialx.emoji.twemoji ''
emoji_generator: !!python/name:materialx.emoji.to_svg ''
- mkdocs-click
extra:
social:
- icon: fontawesome/brands/twitter
Expand Down
41 changes: 11 additions & 30 deletions mkdocs_simple_plugin/generator.py
Expand Up @@ -16,6 +16,14 @@
{% include "versions.snippet" %}
## CLI Reference
::: mkdocs-click
:module: mkdocs_simple_plugin.generator
:command: main
:prog_name: mkdocs_simple_gen
:depth: 2
"""
import os
import tempfile
Expand Down Expand Up @@ -50,13 +58,13 @@ def default_config():
def maybe_set_string(name):
env_variable = "INPUT_" + name.upper()
config_variable = name.lower()
if env_variable in os.environ.keys() and os.environ[env_variable]:
if os.environ.get(env_variable):
config[config_variable] = os.environ[env_variable]

def maybe_set_dict(name, key):
env_variable = "INPUT_" + name.upper()
config_variable = name.lower()
if env_variable in os.environ.keys() and os.environ[env_variable]:
if os.environ.get(env_variable):
config[config_variable] = {key: os.environ[env_variable]}
# Set the config variables via environment if exist
maybe_set_string("site_name")
Expand Down Expand Up @@ -108,7 +116,7 @@ def setup_config(config_file="mkdocs.yml"):
print(config)
if not os.path.exists(config["docs_dir"]):
# Ensure docs directory exists.
print("making docs_dir {}".format(config["docs_dir"]))
print("making docs_dir %s", config["docs_dir"])
os.makedirs(config["docs_dir"], exist_ok=True)

except yaml.YAMLError as exc:
Expand Down Expand Up @@ -136,33 +144,6 @@ def main(config_file, build, serve, mkdocs_args):
os.system("mkdocs serve " + " ".join(args))


""" md
## Usage
```bash
mkdocs_simple_gen
```
### Command line options
See `--help`
```txt
Usage: mkdocs_simple_gen [OPTIONS]
Options:
--config-file Set the configuration file.
--build / --no-build Build the site using mkdocs build.
--serve / --no-serve Serve the site using mkdocs serve.
--help Show this message and exit.
```
default flags:
```bash
mkdocs_simple_gen --no-build --no-serve
```
"""
if __name__ == "__main__":
# pylint doesn't know how to parse the click decorators,
# so disable no-value-for-parameter on main
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Expand Up @@ -4,6 +4,7 @@ Jinja2==3.1.2
MarkupSafe==2.1.1
mkdocs==1.3.0
mkdocs-awesome-pages-plugin==2.7.0
mkdocs-click==0.6.0
mkdocs-macros-plugin==0.7.0
mkdocs-material==8.2.11
mkdocs-simple-hooks==0.1.5
Expand Down
2 changes: 1 addition & 1 deletion tests/test_generator.py
Expand Up @@ -27,7 +27,7 @@ class TestDefaultConfig(unittest.TestCase):
def setUp(self):
"""Set up the tests by reseting the environment variables."""
for var in self.env_variables:
if var in os.environ.keys():
if os.environ.get(var) is not None:
del os.environ[var]

def tearDown(self):
Expand Down

0 comments on commit 1a582ed

Please sign in to comment.