mirror of
https://github.com/onyx-and-iris/obsws-cli.git
synced 2026-04-18 15:03:44 +00:00
first commit
This commit is contained in:
23
obsws_cli/alias.py
Normal file
23
obsws_cli/alias.py
Normal file
@@ -0,0 +1,23 @@
|
||||
"""module defining a custom group class for handling command name aliases."""
|
||||
|
||||
import re
|
||||
|
||||
import typer
|
||||
|
||||
|
||||
class AliasGroup(typer.core.TyperGroup):
|
||||
"""A custom group class to handle command name aliases."""
|
||||
|
||||
_CMD_SPLIT_P = re.compile(r' ?[,|] ?')
|
||||
|
||||
def get_command(self, ctx, cmd_name):
|
||||
"""Get a command by name."""
|
||||
cmd_name = self._group_cmd_name(cmd_name)
|
||||
return super().get_command(ctx, cmd_name)
|
||||
|
||||
def _group_cmd_name(self, default_name):
|
||||
for cmd in self.commands.values():
|
||||
name = cmd.name
|
||||
if name and default_name in self._CMD_SPLIT_P.split(name):
|
||||
return name
|
||||
return default_name
|
||||
Reference in New Issue
Block a user