async2v.cli module¶
Build a command-line interface for your application.
Subclass ApplicationLauncher and override the required methods to configure your components and run your
application without having to write boilerplate.
This gives you the predefined commands run, graph and possibly additional commands provided by
component configurators. In addition, you can also define additional commands by subclassing Command and add them
to your application by registering a subclass of Configurator.
Summary¶
Classes:
ApplicationLauncher |
Main entry point for a async2v commandline application. |
Command |
Abstract base class to define subcommands for the command line interface |
Configurator |
Abstract base class to define reusable command line arguments and configuration parsers |
Reference¶
-
class
Command¶ Bases:
objectAbstract base class to define subcommands for the command line interface
-
__call__(args, app=None)¶ Override to define the command logic.
Parameters: - args – Arguments parsed by argparse
- app (
Optional[Application]) – Holds anApplicationinstance ifneeds_appisTrue, otherwiseNone
Return type: None
-
needs_app¶ Return
Trueif your command requires a fully configuredApplicationinstance.Return type: bool
-
add_arguments(parser)¶ Override to register commandline arguments for this command
Parameters: parser ( ArgumentParser) –Return type: None
-
-
class
Configurator¶ Bases:
objectAbstract base class to define reusable command line arguments and configuration parsers
A configurator can optionally provide one or more subcommands by returning a list of
Commandinstances.-
add_app_arguments(parser)¶ Override to register additional parameters for the application.
Parameters: parser ( ArgumentParser) –Return type: None
-
-
class
ApplicationLauncher¶ Bases:
objectMain entry point for a async2v commandline application.
- To register components, override
register_application_componentsand callapp.register(...). - Some components have predefined configurators that can be hooked into the launcher:
- Override
__init__and callself.add_configurator(...)to register them. - Construct the configuration with
MyConfigurator.config_from_args(...)inregister_application_components.
- Override
- Override
add_app_argumentsto register argparse arguments for your application.
-
add_configurator(configurator)¶ Add a configurator to be evaluated by argparse.
This method needs to be called from the constructor to be effective.
Parameters: configurator ( Configurator) – Configurator provided by a configurableComponent
-
add_app_arguments(parser)¶ Override this method to specify arguments that are needed to construct the application, i.e. when
register_application_componentsis called.Parameters: parser ( ArgumentParser) –
-
register_application_components(args, app)¶ This method must be overridden.
Use
app.register(...)to register your components, using the parsed commandline args.Parameters: - args – Arguments parsed by argparse
- app (
Application) –
-
main(args=None)¶ Launch the commandline interface.
Parameters: args – Optionally pass arguments. If not given, the arguments passed to the program will be parsed.
- To register components, override