Using CMD2 CLI I want to create a command that has a hyphen in the first command.
def do_command_something(self, args):
print("command-something")
I want it to work as below
cmd> command-something
command-something
I have been looking for a while and can not come up with a way within the CMD2 framework to make this work.
Hyphen is not a valid character as an identifier in Python, so you cannot name a method with it directly in the class definition.
Instead, define the
do
method under a different name first, and then usesetattr
on the class object to give the method the desired name with a hyphen. You can delete the original name after that if you want:Demo: https://replit.com/@blhsing1/HealthyConcernedRotation
Test run: