Classful Commands

Command can also be defined with a class, instead of a function.

For example, this command:

examples/hello.py
import arc


@arc.command
def hello(name: str):
    """Greets someone by name"""
    arc.print(f"Hello {name}!")


hello()

Could be written as:

examples/classful.py
import arc


@arc.command
class hello:
    """Greets a person by name"""

    name: str = arc.Argument(desc="Name of the person to greet", default="world")

    def handle(self):
        arc.print(f"Hello, {self.name}!")


hello()
$ python classful.py Joseph
Hello, Joseph!
$ python classful.py --help
USAGE
    classful.py [-h] [name]

DESCRIPTION
    Greets a person by name

ARGUMENTS
    name         Name of the person to greet (default: world)

OPTIONS
    --help (-h)  Displays this help message