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:
object
Abstract 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 anApplication
instance ifneeds_app
isTrue
, otherwiseNone
Return type: None
-
needs_app
¶ Return
True
if your command requires a fully configuredApplication
instance.Return type: bool
-
add_arguments
(parser)¶ Override to register commandline arguments for this command
Parameters: parser ( ArgumentParser
) –Return type: None
-
-
class
Configurator
¶ Bases:
object
Abstract 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
Command
instances.-
add_app_arguments
(parser)¶ Override to register additional parameters for the application.
Parameters: parser ( ArgumentParser
) –Return type: None
-
-
class
ApplicationLauncher
¶ Bases:
object
Main entry point for a async2v commandline application.
- To register components, override
register_application_components
and 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_arguments
to 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_components
is 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