TKTK
Then use argparse subparsers, and do
foo_subparser.set_defaults(func=do_foo)
and then invoke opts.func()
TKTK
Create src/modules/your_module/init.py
In src/modules/your_module/init.py
- Imports
from src.commands import BaseCommand, ToolCommand
- write a class called
Commands(BaseCommand)
- The class should have a property
USAGE
. See examples.
- The
Commands(BaseCommand)
__init__(self, opts: argparse.Namespace):
method should
- Adjust USAGE with
self.command_methods()
. Again, see examples - Assign
self.arg_parser = argparse.ArgumentParser(usage=self.USAGE)
- Do any `self.arg_parser.add_argument() calls for module-specific options
- Call
super().__init__()
- Yes, it needs to come last for module-level--help
to work properly
- Write the command methods, decorated with
@ToolCommand
.
Put the @ToolCommand
decorator from src.util outermost on Commands
class methods to make them show up in the module/command listing produced by running $ cli-tool --list
. It MUST go before (above) other decorators such as @MutuallyExclusiveOptions().
Decorate command methods which have mutually exclusive options like @MutuallyExclusiveOptions(["--yes", "--no"])
to prevent the method being called with options which won't work together.