Skip to content

MkCommandOutput

:fa-brands-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>

Bases: MkTemplate

output property

output: str | None

__init__

__init__(call: Sequence[str], **kwargs: Any) -> None

Parameters:

Name Type Description Default
call Sequence[str]

System call to make

required
kwargs Any

Keyword arguments passed to parent

{}
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
class MkCommandOutput(mktemplate.MkTemplate):
    """Node to display the terminal output of a command."""

    ICON = "material/bash"
    STATUS = "new"
    CSS = [resources.CSSFile("terminal.css")]

    def __init__(self, call: Sequence[str], **kwargs: Any) -> None:
        """Constructor.

        Args:
            call: System call to make
            kwargs: Keyword arguments passed to parent
        """
        self.call = call
        super().__init__("output/html/template", **kwargs)

    @property
    def cwd(self):
        return self.ctx.metadata.repository_path

    def _command_params(self) -> dict[str, Any]:
        cwd = self.cwd
        return dict(call=" ".join(self.call), cwd=str(cwd) if cwd else None)

    def get_input_requests(self) -> list[inputs.InputRequest]:
        return [inputs.InputRequest.create("command", **self._command_params())]

    @property
    def output(self) -> str | None:
        """Output of the command (run in the resolve phase, inputs store kind `command`)."""
        return self.ctx.inputs.get("command", **self._command_params())