diff --git a/mkdocs.yml b/mkdocs.yml index a1c77bba..7244c090 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -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 diff --git a/mkdocs_simple_plugin/generator.py b/mkdocs_simple_plugin/generator.py index 22d27eae..3a4713dc 100644 --- a/mkdocs_simple_plugin/generator.py +++ b/mkdocs_simple_plugin/generator.py @@ -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 @@ -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") @@ -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: @@ -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 diff --git a/requirements.txt b/requirements.txt index 5fa7ea6a..358ffce8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 diff --git a/tests/test_generator.py b/tests/test_generator.py index f0ed461c..de857eb8 100755 --- a/tests/test_generator.py +++ b/tests/test_generator.py @@ -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):