commands.add_command(sub, name, handler, * , needs_spec= True , ** kwargs)
Add one command to the sub-parsers and return its parser.
Parameters
sub
argparse ._SubParsersAction
The object that ArgumentParser.add_subparsers returned.
required
name
str
The command name.
required
handler
Handler
What runs the command; it gets the arguments and the records.
required
needs_spec
bool
Whether the records of regen/ must be loaded first. A command that sets this to False runs without a regen/ tree, and its handler gets None for the records.
True
**kwargs
object
Passed to add_parser (help, description).
{}
Examples
import argparse
from babregen.commands import add_command
parser = argparse.ArgumentParser()
sub = parser.add_subparsers(dest= "command" )
add_command(sub, "hello" , lambda args, spec: 0 , needs_spec= False , help = "say hello" )
args = parser.parse_args(["hello" ])
print (args.command, args.needs_spec)