1
0
mirror of https://github.com/openSUSE/osc.git synced 2024-11-09 22:36:14 +01:00

cmdln: Allow explicitly setting command name

This commit is contained in:
Daniel Mach 2022-10-03 09:46:04 +02:00
parent a68f96fc7f
commit 841353049a

View File

@ -45,6 +45,22 @@ def alias(*aliases):
return decorate
def name(name):
"""
Decorator to explicitly name a Cmdln subcommand.
Example:
class MyShell(cmdln.Cmdln):
@cmdln.name("cmd-with-dashes")
def do_cmd_with_dashes(self, subcmd, opts):
#...
"""
def decorate(f):
f.name = name
return f
return decorate
def hide():
"""
For obsolete calls, hide them in help listings.
@ -134,6 +150,7 @@ class Cmdln:
cmd_func = getattr(self, attr)
# extract data from the function
cmd_name = getattr(cmd_func, "name", cmd_name)
options = getattr(cmd_func, "options", [])
aliases = getattr(cmd_func, "aliases", [])
hidden = getattr(cmd_func, "hidden", False)