I'm using
Typer to write a command line program using python.
Code
Here's an example script of were I'm running into trouble.
import typer
app = typer.Typer()
@app.command()
def hello(name):
typer.echo(f'Hello!')
@app.command()
def goodbye():
typer.echo(f'Goodbye.')
class Grettings:
@app.command()
def aloha(self):
typer.echo('Aloha!')
@app.command()
def bonjour(self):
typer.echo('Bonjour!')
if __name__ == '__main__':
app()
When the following commands are entered into the terminal the expected output is given.
python main.py hello
python main.py goodbye
Issue
However, when the class methods are called, I get the following exception.
python main.py aloha
python main.py bonjour
Usage: main.py aloha [OPTIONS] SELF
Try 'main.py aloha --help' for help.
Error: Missing argument 'SELF'.
Clearly, this is from the class not being initialized, yet. But it seems like it'd be a common problem, so I assume there's a simple solution to the issue.
Research
Possible solutions I've found include using decorators on the class/methods being used, or using a special class that'd need to be inherited to "expose" the class methods.
Hint from answer of Can a decorator of an instance method access the class? :
Any decorator is called BEFORE class is built, so is unknown to the decorator.