API¶
-
argvard.
__version__
¶ The version as a string.
-
argvard.
__version_info__
¶ The version as a tuple, containing the major, minor, and bugfix version. You should this, if you need to implement any version checks.
Application Object¶
-
class
argvard.
Argvard
(defaults=None)¶ The argvard object is the central object of the command line application.
Instances are callable with the command line arguments,
sys.argv
by default.The object acts as a registry for options and commands and calls them as necessary.
Parameters: defaults – A dictionary containing the initial values for the context. -
main
(signature='')¶ A decorator that is used to register the main function with the given signature:
@app.main() def main(context): # do something pass
The main function is called, after any options and if no command has been called.
-
option
(signature, overrideable=False)¶ A decorator for registering an option with the given signature:
@app.option('--option') def option(context): # do something pass
If the name in the signature has already been used to register an option, a
RuntimeError
is raised unless the registered option has been defined with overrideable set to True.Parameters: - signature – The signature of the option as a string.
- overrideable – If True the registered option can be overridden.
-
register_command
(name, command)¶ Registers the command with the given name.
If the name has already been used to register a command a
RuntimeError
will be raised.
-
Command Object¶
-
class
argvard.
Command
(defaults=None)¶ A command - like an argvard object - is a registry of options and commands, that represents a distinct action.
Commands can be registered with any number of argvard objects, any number of times (under different names.)
Parameters: defaults – A dictionary containing the initial values for the context, any values already contained in the context once the command is called will not be overridden with a default value. -
main
(signature='')¶ A decorator that is used to register the main function with the given signature:
@app.main() def main(context): # do something pass
The main function is called, after any options and if no command has been called.
-
option
(signature, overrideable=False)¶ A decorator for registering an option with the given signature:
@app.option('--option') def option(context): # do something pass
If the name in the signature has already been used to register an option, a
RuntimeError
is raised unless the registered option has been defined with overrideable set to True.Parameters: - signature – The signature of the option as a string.
- overrideable – If True the registered option can be overridden.
-
register_command
(name, command)¶ Registers the command with the given name.
If the name has already been used to register a command a
RuntimeError
will be raised.
-
Context Object¶
-
class
argvard.
Context
(argvard, application_name)¶ The context object is a dictionary, passed to options and main functions, which they can use to store information.
It further provides information useful for introspection and debugging through attributes.
-
argvard
¶ The current application.
-
command
¶ The current command or None.
-
command_path
¶ A list containing the name of the application and the names of all commands called so far.
-
caller
¶ The current command or argvard object.
-