You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* The class must extend the util.cmd.Command class
* Arguments and resources are injected by means of annotated methods
* We use an output stream to write data
* The class can be reused in different environments because it is not
dependant on anything console-specific.
This annotation marks methods as parameter acceptors.
* Methods that wish to accept a command line argument must have exactly
one argument.
* This argument may have a default value.
* If the method does not have a default value, the parameter passing
stops hard at this point.
* Otherwise, the method is invoked without arguments, so that the
default value will be passed.
This method will be called only if --debug is supplied.
The argument name is calculated by using a lowercase version of the
method name and stripping a leading "set".
Note for cases 2), 3) and 4): The short argument's name is calculated by using
the first character of the long argument's name. It can be overwritten to
resolve ambiguous names by adding a short= '[CHARACTER]' to the @arg
annotation.
This annotation marks methods as resource injectors.
* Resources are one of the following: database connections, logger
categories, properties.
* Resources are configured by property objects:
- The property manager's lookup path is set to "etc/" per default
and may be set via xpcli -c <path>
- The connection manager is configured by database.ini
- The logger is configured by log.ini
Scope of Change
A runner script (similar to the unittest runner) will be created to run
classes as scripts.
Rationale
Simplify command line utilities development.
Functionality
Overview
Instead of writing a complete script we now declare a class as follows:
We can run this class by using the cli-runner:
Rules
The xpcli runner
Usage:
The runner-args are any arguments beginning with a dash ("-"). The class
name argument is the first argument without a dash in front of it.
Runner-args:
Class-args:
The runner goes through the following steps when invoked:
Extract runner arguments
Load command class
Check for -? or --help and show a usage
Configure the property manager
In case a database.ini exists in the property manager's configuration
file path, configure the connection manager with it
In case a log.ini exists in the property manager's configuration
file path, configure the logger with it
Perform dependency injection. In case an exception is thrown from any
of the methods, stop.
Pass arguments. In case an argument is missing or an exception is thrown
from any of the methods, stop.
Invoke the run() method
The util.cmd.Command class
The out and err members are created by the runner and are
PrintOutputStream objects. For the console runner, they write data
to STDOUT and STDERR.
The @arg annotation
This annotation marks methods as parameter acceptors.
How to accept arguments:
This will take the first command line argument
This will take the value passed as --verbosity= or -v
This will take the value passed as --classname= or -c
The argument name is calculated by using a lowercase version of the
method name and stripping a leading "set".
This method will be called only if --debug is supplied.
The argument name is calculated by using a lowercase version of the
method name and stripping a leading "set".
The @Inject annotation
This annotation marks methods as resource injectors.
This method will receive a DBConnection instance (via
ConnectionManager::getInstance()->getByHost('news', 0))
This method will receive a LogCategory instance (via
Logger::getInstance()->getCategory('default'))
This method will receive a LogCategory instance (via
PropertyManager::getInstance()->getProperties('app'))
Security considerations
n/a
Speed impact
n/a
Dependencies
I/O Streams API
Related documents
Experiment
Download (contains xpcli.php and supporting classes for PHP5)
The text was updated successfully, but these errors were encountered: