Skip to content

cli

KindFilter

Bases: str, Enum

The element types that can be filtered on from the command line.

ElementType is not usable directly here, as its integer values would become the choices offered on the command line.

element_type property

element_type

The element type this choice selects.

show

show(name=None, kind=None)

Show available SGN elements or information about a plugin or element.

A name that is both a plugin and an element resolves to the plugin.

Source code in src/sgn_inspect/cli.py
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
@app.command()
def show(
    name: Annotated[
        str | None,
        Argument(
            metavar="[ELEMENT | PLUGIN | PATTERN]",
            help=(
                "If specified, an element or plugin name, or a glob pattern to "
                "match element names against. Otherwise list all elements"
            ),
            autocompletion=_complete_name,
        ),
    ] = None,
    kind: Annotated[
        KindFilter | None,
        Option(
            "--type",
            "-t",
            case_sensitive=False,
            help="Only list elements of this type",
        ),
    ] = None,
) -> None:
    """Show available SGN elements or information about a plugin or element.

    A name that is both a plugin and an element resolves to the plugin.
    """
    elements = discover_elements()
    pattern = name if name is not None and _is_pattern(name) else None

    if name is not None and pattern is None:
        elements_by_plugin: dict[str, dict[str, ElementInfo]] = defaultdict(dict)
        for info in elements.values():
            elements_by_plugin[info.plugin][info.name] = info
        if name in elements_by_plugin:
            # display per-plugin information
            plugin_elements = elements_by_plugin[name]
            _display_plugin_info(plugin_elements, kind)
            if name in elements:
                _display_shadowed_note(elements[name])
            if kind is not None and not _of_type(plugin_elements, kind):
                raise Exit(code=1)
        elif name in elements:
            # display element information
            info = elements[name]
            _display_element_info(info)
        else:
            _display_unknown_name(name, elements, elements_by_plugin)
            raise Exit(code=1)
        return

    if pattern is not None:
        elements = _matching(elements, pattern)
    if kind is not None:
        elements = _of_type(elements, kind)
    if not elements:
        console.print(_no_match_text(kind, pattern))
        raise Exit(code=1)
    _display_all_element_info(elements, _filter_text(kind, pattern))