MkCommandOutput

github Show source on GitHub

Node to display the terminal output of a command.

Example: Regular

Jinja

{{ ["hatch", "--help"] | MkCommandOutput }}

Python

MkCommandOutput(['hatch', '--help'])
hatch --help /bin/sh: 1: hatch: not found
<div data-terminal>
  <span data-ty="input">hatch --help</span>
  <span data-ty>/bin/sh: 1: hatch: not found</span>
</div>
<div data-terminal>
  <span data-ty="input">hatch --help</span>
  <span data-ty>/bin/sh: 1: hatch: not found</span>
</div>

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

[[resources.css]]
filename = "terminal.css"

[examples.regular]
condition = "{{ 'CI' | getenv }}"
title = "Regular"
jinja = """
{{ ["hatch", "--help"] | MkCommandOutput }}
"""

[output.html]
template = """
<div data-terminal>
  <span data-ty="input">{{ node.call | join(" ") }}</span>
  <span data-ty>{{ node.output }}</span>
</div>
"""
mknodes.templatenodes.mkcommandoutput.MkCommandOutput
14class MkCommandOutput(mktemplate.MkTemplate):
15    """Node to display the terminal output of a command."""
16
17    ICON = "material/bash"
18    STATUS = "new"
19    CSS = [resources.CSSFile("terminal.css")]
20
21    def __init__(self, call: Sequence[str], **kwargs: Any) -> None:
22        """Constructor.
23
24        Args:
25            call: System call to make
26            kwargs: Keyword arguments passed to parent
27        """
28        self.call = call
29        super().__init__("output/html/template", **kwargs)
30
31    @property
32    def cwd(self):
33        return self.ctx.metadata.repository_path
34
35    def _command_params(self) -> dict[str, Any]:
36        cwd = self.cwd
37        return dict(call=" ".join(self.call), cwd=str(cwd) if cwd else None)
38
39    def get_input_requests(self) -> list[inputs.InputRequest]:
40        return [inputs.InputRequest.create("command", **self._command_params())]
41
42    @property
43    def output(self) -> str | None:
44        """Output of the command (run in the resolve phase, inputs store kind `command`)."""
45        return self.ctx.inputs.get("command", **self._command_params())
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/bash
status: new
title: MkCommandOutput