lib.Cmd.AbstractCmd.aliases: Add property
Add a property aliases to AbstractCmd in prepeparation for commands to bear multiple names / abbreviations / aliases.
The App.add_cmds_to_parser() function uses parse_known_args() to determine which subcommand was invoked, then conditionally registers nested subcommands. The lookup dictionary (scs) contains only canonical names, not aliases, so add them too, otherwise using the alias instead of the canonical name causes the lookup to fail and nested subcommands to never be registered.
Fix: Register each alias in scs pointing to the same SubCommand object, and deduplicate with id(sc) when iterating in all=True mode to avoid infinite recursion on help output.
Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
4e347683ef
commit
3b0f7727a7
3 changed files with 35 additions and 7 deletions
|
|
@ -6,12 +6,19 @@ from ..App import App as Parent
|
|||
from ..CmdBase import CmdBase as Base
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from typing import Iterable
|
||||
from ..lib.Distro import Distro
|
||||
|
||||
class Cmd(Base): # export
|
||||
|
||||
def __init__(self, parent: Parent, name: str, help: str) -> None:
|
||||
super().__init__(parent, name, help)
|
||||
def __init__(
|
||||
self,
|
||||
parent: Parent,
|
||||
name: str,
|
||||
help: str,
|
||||
aliases: Iterable[str] | None = None
|
||||
) -> None:
|
||||
super().__init__(parent, name, help, aliases = aliases)
|
||||
|
||||
async def _run(self, args):
|
||||
# Missing subcommand
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue