MkCliDoc

github Show source on GitHub

Node for showing documentation for click / typer CLI apps.

Example: MkDocs-MkNodes CLI

Jinja

{{ "mknodes.cli:cli" | MkCliDoc }}

Python

MkCliDoc('mknodes.cli:cli')

mknodes

MkNodes: build documentation from Python node trees.

generate writes the pages (and the site config), build / serve also run the site engine. Docs: https://phil65.github.io/mknodes/

mknodes [OPTIONS] COMMAND [ARGS]...

--install-completion

flag Flag Install completion for the current shell.

--show-completion

flag Flag Show completion for the current shell, to copy it or customize the installation.

--help

flag Flag Show this message and exit.

## mknodes

MkNodes: build documentation from Python node trees.

`generate` writes the pages (and the site config), `build` / `serve` also run the site engine. Docs: https://phil65.github.io/mknodes/

````python
mknodes [OPTIONS] COMMAND [ARGS]...
````

### `--install-completion`

<img src="https://api.iconify.design/mdi/flag.svg?height=16" alt="flag"> <code>Flag</code>
Install completion for the current shell.

### `--show-completion`

<img src="https://api.iconify.design/mdi/flag.svg?height=16" alt="flag"> <code>Flag</code>
Show completion for the current shell, to copy it or customize the installation.

### `--help`

<img src="https://api.iconify.design/mdi/flag.svg?height=16" alt="flag"> <code>Flag</code>
Show this message and exit.
<h2>mknodes</h2>
<p>MkNodes: build documentation from Python node trees.</p>
<p><code>generate</code> writes the pages (and the site config), <code>build</code> / <code>serve</code> also run the site engine. Docs: https://phil65.github.io/mknodes/</p>
<pre><code class="language-python">mknodes [OPTIONS] COMMAND [ARGS]...
</code></pre>
<h3><code>--install-completion</code></h3>
<p><img src="https://api.iconify.design/mdi/flag.svg?height=16" alt="flag"> <code>Flag</code>
Install completion for the current shell.</p>
<h3><code>--show-completion</code></h3>
<p><img src="https://api.iconify.design/mdi/flag.svg?height=16" alt="flag"> <code>Flag</code>
Show completion for the current shell, to copy it or customize the installation.</p>
<h3><code>--help</code></h3>
<p><img src="https://api.iconify.design/mdi/flag.svg?height=16" alt="flag"> <code>Flag</code>
Show this message and exit.</p>
MkCliDoc
├── MkHeader('mknodes')
├── MkCode(None)
│   ╰── MkText('mknodes [OPTIONS] COMMAND [ARGS]...')
╰── MkHeader('`--install-completion`', level=3)
├── MkMaterialBadge('mdi:flag', 'Flag')
╰── MkHeader('`--show-completion`', level=3)
├── MkMaterialBadge('mdi:flag', 'Flag')
╰── MkHeader('`--help`', level=3)
╰── MkMaterialBadge('mdi:flag', 'Flag')

Example: SubCommand

Jinja

{{ "mknodes.cli:cli" | MkCliDoc(prog_name="build") }}

Python

MkCliDoc('mknodes.cli:cli', prog_name='build')

build

Build a MkNodes-based website, locally or remotely.

Runs the build function on given repository (either locally or a hosted one), writes the generated pages and config (see generate) and builds the HTML website with the engine (zensical build -f <generated config>, mkdocs build -f ..., mdbook build <book dir>, sphinx-build <source dir> <site dir>). Docsify has no build step: the generated site dir is the website.

Problems which leave pages broken (build diagnostics) get logged as warnings and summarized at the end; in strict mode they fail the build.

Further info here: https://phil65.github.io/mknodes/CLI/

mknodes build [OPTIONS]

--repo-url, -r

Repository URL of the target package. Can be remote or local.

--build-fn, -b

Path to the build script. (form: path.to.module:function )

--site-dir, -d

Path to the folder where the HTML should get written.

--clone-depth, -c

Git clone depth in case repository is remote. Important for changelog generation.

--config-path, -p

Default: mkdocs.yml Path to the config file.

--strict, -s

flag Flag Strict mode: fail if the build reported problems (failed nodes, /// mknodes or python exec blocks, broken code fences, unresolved references). Also passed to the engine. Default: the strict setting.

--engine, -e

Default: zensical Site engine: zensical (HTML site, default), mkdocs (HTML site, needs the mkdocs extra), mdbook (HTML book, needs the mdbook binary to build / serve), sphinx (HTML site from MyST Markdown, needs the sphinx extra), docsify (Markdown rendered in the browser, no build step) or markdown (plain Markdown files).

--flavor

Markdown flavour (material, github, mdbook, myst). Default: the engine’s flavour (zensical / mkdocs: material, mdbook: mdbook, sphinx: myst, docsify / markdown: github).

--jinja-engine

Template engine for the Jinja templates: jinja2 (default) or minijinja (needs the minijinja extra). Default: jinja_engine of [tool.mknodes], else the MKNODES_JINJA_ENGINE environment variable, else jinja2.

--offline

flag Flag Take external inputs (icons, licenses, LLM texts) only from the lock file (mknodes.lock): fail if one is missing, never write the lock file.

--refresh-inputs

flag Flag Fetch all external inputs again and rewrite the lock file with exactly the used ones.

--verbose, -v

flag Flag Enable verbose output. (DEBUG level)

--quiet, -q

flag Flag Suppress output.

--help

flag Flag Show this message and exit.

## build

Build a MkNodes-based website, locally or remotely.

Runs the build function on given repository (either locally or a hosted one),
writes the generated pages and config (see `generate`) and builds the HTML website
with the engine (`zensical build -f <generated config>`, `mkdocs build -f ...`,
`mdbook build <book dir>`, `sphinx-build <source dir> <site dir>`). Docsify has no
build step: the generated site dir is the website.

Problems which leave pages broken (build diagnostics) get logged as warnings and
summarized at the end; in strict mode they fail the build.

Further info here: https://phil65.github.io/mknodes/CLI/

````python
mknodes build [OPTIONS]
````

### `--repo-url`, `-r`

Repository URL of the target package. Can be remote or local.

### `--build-fn`, `-b`

Path to the build script. (form: `path.to.module:function` )

### `--site-dir`, `-d`

Path to the folder where the HTML should get written.

### `--clone-depth`, `-c`

Git clone depth in case repository is remote. Important for changelog generation.

### `--config-path`, `-p`

**Default:** mkdocs.yml
Path to the config file.

### `--strict`, `-s`

<img src="https://api.iconify.design/mdi/flag.svg?height=16" alt="flag"> <code>Flag</code>
Strict mode: fail if the build reported problems (failed nodes, `/// mknodes` or `python exec` blocks, broken code fences, unresolved references). Also passed to the engine. Default: the `strict` setting.

### `--engine`, `-e`

**Default:** zensical
Site engine: `zensical` (HTML site, default), `mkdocs` (HTML site, needs the `mkdocs` extra), `mdbook` (HTML book, needs the `mdbook` binary to build / serve), `sphinx` (HTML site from MyST Markdown, needs the `sphinx` extra), `docsify` (Markdown rendered in the browser, no build step) or `markdown` (plain Markdown files).

### `--flavor`

Markdown flavour (`material`, `github`, `mdbook`, `myst`). Default: the engine's flavour (zensical / mkdocs: `material`, mdbook: `mdbook`, sphinx: `myst`, docsify / markdown: `github`).

### `--jinja-engine`

Template engine for the Jinja templates: `jinja2` (default) or `minijinja` (needs the `minijinja` extra). Default: `jinja_engine` of [tool.mknodes], else the MKNODES_JINJA_ENGINE environment variable, else jinja2.

### `--offline`

<img src="https://api.iconify.design/mdi/flag.svg?height=16" alt="flag"> <code>Flag</code>
Take external inputs (icons, licenses, LLM texts) only from the lock file (`mknodes.lock`): fail if one is missing, never write the lock file.

### `--refresh-inputs`

<img src="https://api.iconify.design/mdi/flag.svg?height=16" alt="flag"> <code>Flag</code>
Fetch all external inputs again and rewrite the lock file with exactly the used ones.

### `--verbose`, `-v`

<img src="https://api.iconify.design/mdi/flag.svg?height=16" alt="flag"> <code>Flag</code>
Enable verbose output. (`DEBUG` level)

### `--quiet`, `-q`

<img src="https://api.iconify.design/mdi/flag.svg?height=16" alt="flag"> <code>Flag</code>
Suppress output.

### `--help`

<img src="https://api.iconify.design/mdi/flag.svg?height=16" alt="flag"> <code>Flag</code>
Show this message and exit.
<h2>build</h2>
<p>Build a MkNodes-based website, locally or remotely.</p>
<p>Runs the build function on given repository (either locally or a hosted one),
writes the generated pages and config (see <code>generate</code>) and builds the HTML website
with the engine (<code>zensical build -f &lt;generated config&gt;</code>, <code>mkdocs build -f ...</code>,
<code>mdbook build &lt;book dir&gt;</code>, <code>sphinx-build &lt;source dir&gt; &lt;site dir&gt;</code>). Docsify has no
build step: the generated site dir is the website.</p>
<p>Problems which leave pages broken (build diagnostics) get logged as warnings and
summarized at the end; in strict mode they fail the build.</p>
<p>Further info here: https://phil65.github.io/mknodes/CLI/</p>
<pre><code class="language-python">mknodes build [OPTIONS]
</code></pre>
<h3><code>--repo-url</code>, <code>-r</code></h3>
<p>Repository URL of the target package. Can be remote or local.</p>
<h3><code>--build-fn</code>, <code>-b</code></h3>
<p>Path to the build script. (form: <code>path.to.module:function</code> )</p>
<h3><code>--site-dir</code>, <code>-d</code></h3>
<p>Path to the folder where the HTML should get written.</p>
<h3><code>--clone-depth</code>, <code>-c</code></h3>
<p>Git clone depth in case repository is remote. Important for changelog generation.</p>
<h3><code>--config-path</code>, <code>-p</code></h3>
<p><strong>Default:</strong> mkdocs.yml
Path to the config file.</p>
<h3><code>--strict</code>, <code>-s</code></h3>
<p><img src="https://api.iconify.design/mdi/flag.svg?height=16" alt="flag"> <code>Flag</code>
Strict mode: fail if the build reported problems (failed nodes, <code>/// mknodes</code> or <code>python exec</code> blocks, broken code fences, unresolved references). Also passed to the engine. Default: the <code>strict</code> setting.</p>
<h3><code>--engine</code>, <code>-e</code></h3>
<p><strong>Default:</strong> zensical
Site engine: <code>zensical</code> (HTML site, default), <code>mkdocs</code> (HTML site, needs the <code>mkdocs</code> extra), <code>mdbook</code> (HTML book, needs the <code>mdbook</code> binary to build / serve), <code>sphinx</code> (HTML site from MyST Markdown, needs the <code>sphinx</code> extra), <code>docsify</code> (Markdown rendered in the browser, no build step) or <code>markdown</code> (plain Markdown files).</p>
<h3><code>--flavor</code></h3>
<p>Markdown flavour (<code>material</code>, <code>github</code>, <code>mdbook</code>, <code>myst</code>). Default: the engine's flavour (zensical / mkdocs: <code>material</code>, mdbook: <code>mdbook</code>, sphinx: <code>myst</code>, docsify / markdown: <code>github</code>).</p>
<h3><code>--jinja-engine</code></h3>
<p>Template engine for the Jinja templates: <code>jinja2</code> (default) or <code>minijinja</code> (needs the <code>minijinja</code> extra). Default: <code>jinja_engine</code> of [tool.mknodes], else the MKNODES_JINJA_ENGINE environment variable, else jinja2.</p>
<h3><code>--offline</code></h3>
<p><img src="https://api.iconify.design/mdi/flag.svg?height=16" alt="flag"> <code>Flag</code>
Take external inputs (icons, licenses, LLM texts) only from the lock file (<code>mknodes.lock</code>): fail if one is missing, never write the lock file.</p>
<h3><code>--refresh-inputs</code></h3>
<p><img src="https://api.iconify.design/mdi/flag.svg?height=16" alt="flag"> <code>Flag</code>
Fetch all external inputs again and rewrite the lock file with exactly the used ones.</p>
<h3><code>--verbose</code>, <code>-v</code></h3>
<p><img src="https://api.iconify.design/mdi/flag.svg?height=16" alt="flag"> <code>Flag</code>
Enable verbose output. (<code>DEBUG</code> level)</p>
<h3><code>--quiet</code>, <code>-q</code></h3>
<p><img src="https://api.iconify.design/mdi/flag.svg?height=16" alt="flag"> <code>Flag</code>
Suppress output.</p>
<h3><code>--help</code></h3>
<p><img src="https://api.iconify.design/mdi/flag.svg?height=16" alt="flag"> <code>Flag</code>
Show this message and exit.</p>
MkCliDoc
├── MkHeader('build')
├── MkCode(None)
│   ╰── MkText('mknodes build [OPTIONS]')
├── MkHeader('`--repo-url`, `-r`', level=3)
├── MkHeader('`--build-fn`, `-b`', level=3)
├── MkHeader('`--site-dir`, `-d`', level=3)
├── MkHeader('`--clone-depth`, `-c`', level=3)
├── MkHeader('`--config-path`, `-p`', level=3)
╰── MkHeader('`--strict`, `-s`', level=3)
├── MkMaterialBadge('mdi:flag', 'Flag')
├── MkHeader('`--engine`, `-e`', level=3)
├── MkHeader('`--flavor`', level=3)
├── MkHeader('`--jinja-engine`', level=3)
╰── MkHeader('`--offline`', level=3)
├── MkMaterialBadge('mdi:flag', 'Flag')
╰── MkHeader('`--refresh-inputs`', level=3)
├── MkMaterialBadge('mdi:flag', 'Flag')
╰── MkHeader('`--verbose`, `-v`', level=3)
├── MkMaterialBadge('mdi:flag', 'Flag')
╰── MkHeader('`--quiet`, `-q`', level=3)
├── MkMaterialBadge('mdi:flag', 'Flag')
╰── MkHeader('`--help`', level=3)
╰── MkMaterialBadge('mdi:flag', 'Flag')

class MkCliDoc(mktemplate.MkTemplate)
graph TD
  3586431358["mkclidoc.MkCliDoc"]
  1289759389["mktemplate.MkTemplate"]
  3160803176["rendercache.TemplateRenderMixin"]
  2751680898["builtins.object"]
  835538629["mkcontainer.MkContainer"]
  1956333208["mkcontainer.MkContainerBase"]
  1359323199["mknode.MkNode"]
  1289759389 --> 3586431358
  3160803176 --> 1289759389
  2751680898 --> 3160803176
  835538629 --> 1289759389
  1956333208 --> 835538629
  1359323199 --> 1956333208
  2751680898 --> 1359323199
/home/runner/work/mknodes/mknodes/src/mknodes/basenodes/mkclidoc/metadata.toml
[metadata]
icon = "mdi:api"
name = "MkCliDoc"

[examples.cli]
title = "MkDocs-MkNodes CLI"
jinja = """
{{ "mknodes.cli:cli" | MkCliDoc }}
"""

[examples.sub_command]
title = "SubCommand"
jinja = """
{{ "mknodes.cli:cli" | MkCliDoc(prog_name="build") }}
"""

[examples.argparse]
title = "ArgumentParser"
python = """
import git_changelog
import mknodes as mk

parser = git_changelog.get_parser()
mk.MkCliDoc(parser)
"""

[fragments]
param_template = """
{{ param.opt_str | MkHeader(level=3) }}

{% if param.required %}
"{{ "REQUIRED" | md_style(bold=True) }}"
{% endif %}
{% if param.envvar %}
Environment variable{{ param.envvar }}
{% endif %}
{% if param.multiple %}
{{ "Multiple values allowed." | md_style(bold=True) }}
{% endif %}
{% if param.default %}
{{ "Default:" | md_style(bold=True) }} {{ param.default }}
{% endif %}
{% if param.is_flag %}
{{ "mdi:flag" | MkMaterialBadge("Flag") }}
{% endif %}
{% if param.help %}
{{ param.help }}
{% endif %}
"""
command_template = """
{{ info.name | MkHeader }}

{{ info.description }}

{{ info.usage | MkCode }}

{% for param in info.params %}
{{ "fragments/param_template" | render_template(param=param) }}

{% endfor %}

"""

[output.markdown]
template = """
{% if node.info %}
{{ "fragments/command_template" | render_template(info=node.info) }}
{% if node.show_subcommands %}
{% for sub_info in node.info.subcommands.values() %}
{{ "fragments/command_template" | render_template(info=sub_info) }}
{% endfor %}
{% endif %}
{% endif %}
"""
mknodes.basenodes.mkclidoc.MkCliDoc
14class MkCliDoc(mktemplate.MkTemplate):
15    """Node for showing documentation for click / typer CLI apps."""
16
17    ICON = "material/api"
18
19    def __init__(
20        self,
21        target: str | argparse.ArgumentParser | None = None,
22        *,
23        prog_name: str | None = None,
24        show_hidden: bool = False,
25        show_subcommands: bool = False,
26        **kwargs: Any,
27    ) -> None:
28        r"""Constructor.
29
30        Args:
31            target: Dotted path to click group / typer instance / ArgumentParser
32            prog_name: Program name
33            show_hidden: Show commands and options that are marked as hidden.
34            show_subcommands: List subcommands of a given command.
35            kwargs: Keyword arguments passed to parent
36        """
37        super().__init__("output/markdown/template", **kwargs)
38        self.target = target
39        self.prog_name = prog_name
40        self.show_hidden = show_hidden
41        self.show_subcommands = show_subcommands
42
43    @property
44    def info(self) -> clinspector.CommandInfo | None:
45        import importlib
46
47        match self.target:
48            case str():
49                module, command = self.target.split(":")
50                prog_name = self.prog_name
51                mod = importlib.import_module(module)
52                instance = getattr(mod, command)
53            case None:
54                if cli_eps := self.ctx.metadata.entry_points.get_group("console_scripts"):
55                    module, command = cli_eps[0].value.split(":")
56                    prog_name = cli_eps[0].name
57                    mod = importlib.import_module(module)
58                    instance = getattr(mod, command)
59                else:
60                    return None
61            case _:
62                instance = self.target
63                prog_name = self.prog_name
64        return clinspector.get_cmd_info(instance, command=prog_name)
Page info
Code for this page
mknodes.manual.nodes_section.create_section_for_nodes
 93def create_section_for_nodes(
 94    nav: mk.MkNav,
 95    klasses: Sequence[type[mk.MkNode]],
 96) -> mk.MkTable:
 97    table = mk.MkTable(columns=["Node", "Docstrings", "Markdown extensions"])
 98    for kls in klasses:
 99        tpl = "classpage_custom.jinja"
100        page = mk.MkClassPage(kls, icon=kls.ICON, template_path=tpl, parent=nav, hide="toc")
101        nav += page
102        if kls.STATUS:
103            page.metadata.status = kls.STATUS
104        elif kls.JS_FILES:
105            page.metadata.status = "js"
106        elif kls.CSS:
107            page.metadata.status = "css"
108        page.created_by = create_section_for_nodes
109        link = mk.MkLink(page, kls.__name__, icon=kls.ICON)
110        extensions = ", ".join(f"`{i}`" for i in kls.REQUIRED_EXTENSIONS)
111        table.add_row((link, kls.__doc__, extensions))
112    return table
Resources
Resources(css=[],
          markdown_extensions={'admonition': {},
                               'pymdownx.details': {},
                               'pymdownx.highlight': {'anchor_linenums': True,
                                                      'line_spans': '__span',
                                                      'pygments_lang_class': True},
                               'pymdownx.superfences': {'custom_fences': [{'class': 'mermaid',
                                                                           'format': <function fence_code_format at 0x7ff77e88b060>,
                                                                           'name': 'mermaid'}]},
                               'pymdownx.tabbed': {},
                               'tables': {}},
          plugins=[Plugin('mkdocstrings')],
          js=[],
          assets=[],
          packages=[])
Metadata
created:
  source_filename: /home/runner/work/mknodes/mknodes/src/mknodes/manual/nodes_section.py
  source_function: create_section_for_nodes
  source_line_no: 93
hide:
- toc
icon: material/api
status: new
title: MkCliDoc