hazwaz.command module

class hazwaz.command.Command[source]

Bases: object

A subcommand to a MainCommand.

Every subcommand of your script will be a subclass of this, added to the MainCommand.subcommands.

add_arguments(parser: ArgumentParser)[source]

Add argparse arguments to an existing parser.

Override this method to add arguments to a subcommand.

main()[source]

Main code of this subcommand.

Override this method to implement the actual program.

name: Optional[str] = None

The name used to call this subcommand from the command line.

If this property is none, the default is the name of the class set to lowercase.

class hazwaz.command.MainCommand[source]

Bases: object

The main class for a command line command.

Your script will have to subclass this once, instantiate and run its run() e.g. as:

class MyCommand(MainCommand):
    """
    A description that will be used in the help.
    """

if __name__ == "__main__":
    MyCommand().run()
add_arguments(parser: ArgumentParser)[source]

Add argparse arguments to an existing parser.

If you need to override this method, you probably want to call super().add_arguments(parser) to add the default arguments.

coloredlogs: bool = True

Whether coloredlogs is used (if available)

commands: Iterable[Command] = ()

The subcommands: a tuple of Command subclasses.

logformat: str = '%(levelname)s:%(name)s: %(message)s'

The format passed to logging.Formatter.

main()[source]

The main function for a command with no subcommands.

This default implementation that simply prints the help is good for most cases when there are subcommands and running the bare command doesn’t do anything.

run()[source]

Run the command.

This is the method called to start running the command.

setup_logging()[source]