command_decorator¶
-
class
argdeco.command_decorator.
CommandDecorator
(*args, **kwargs)[source]¶ Create a decorator to decorate functions with their arguments.
-
add_command
(command, *args, **kwargs)[source]¶ add a command.
This is basically a wrapper for add_parser()
-
add_subcommands
(command, *args, **kwargs)[source]¶ add subcommands.
If command already defined, pass args and kwargs to add_subparsers() method, else to add_parser() method. This behaviour is for convenience, because I mostly use the sequence:
>>> p = parser.add_parser('foo', help="some help") >>> subparser = p.add_subparsers()
If you want to configure your sub_parsers, you can do it with:
>>> command.add_subcommands('cmd', help = "cmd help" subcommands = dict( title = "title" description = "subcommands description" ) )
-
execute
(argv=None, compile=None, preprocessor=None, compiler_factory=None)[source]¶ Parse arguments and execute decorated function
argv: list of arguments compile:
- None, pass args as keyword args to function
- True, pass args as single dictionary
- function, get args from parse_args() and return a pair of tuple and dict to be passed as args and kwargs to function
-
get_config_name
(action, name=None)[source]¶ get the name for configuration
This returns a name respecting commands and subcommands. So if you have a command name “index” with subcommand “ls”, which has option “–all”, you will pass the action for subcommand “ls” and the options’s dest name (“all” in this case), then this function will return “index.ls.all” as configuration name for this option.
-