dirigent-cli 0.9.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ """The dirigent command line interface, installed as `dirigent` and `dg`."""
2
+
3
+ from dirigent_cli.main import app, run
4
+
5
+ __all__ = ["app", "run"]
@@ -0,0 +1,41 @@
1
+ """Hidden aliases: ``ls`` for every ``list`` in the tree, and one for a single command."""
2
+
3
+ from typing import Final
4
+
5
+ import typer
6
+
7
+ LIST_COMMAND: Final = "list"
8
+ LIST_ALIAS: Final = "ls"
9
+
10
+
11
+ def add_list_aliases(app: typer.Typer, *, alias: str = LIST_ALIAS) -> list[str]:
12
+ """Register a hidden ``ls`` beside every ``list`` in an app and its groups.
13
+
14
+ Call after the whole tree is assembled; commands registered later are not walked.
15
+ """
16
+ aliased: list[str] = []
17
+ for group in app.registered_groups:
18
+ inner = group.typer_instance
19
+ if inner is not None:
20
+ aliased.extend(
21
+ f"{group.name or inner.info.name or '?'} {name}" for name in add_list_aliases(inner, alias=alias)
22
+ )
23
+ if any(command.name == alias for command in app.registered_commands):
24
+ return aliased
25
+ for command in list(app.registered_commands):
26
+ if command.name != LIST_COMMAND or command.callback is None:
27
+ continue
28
+ app.command(alias, hidden=True, help=command.help)(command.callback)
29
+ aliased.append(alias)
30
+ return aliased
31
+
32
+
33
+ def add_alias(app: typer.Typer, name: str, alias: str, *, hidden: bool = True) -> None:
34
+ """Register a second name for one command, so muscle memory from another tool still lands."""
35
+ for command in list(app.registered_commands):
36
+ # A command registered without a name is named after its function, as typer does it.
37
+ called = command.callback
38
+ if called is not None and name in (command.name, called.__name__):
39
+ app.command(alias, hidden=hidden, help=command.help)(called)
40
+ return
41
+ raise LookupError(f"no command named {name!r} to alias")