Constructor.
Alias of Application, for use by sub-classes without needing to import ocean.util.app.Application.
Exit cleanly from the application.
Runs the application.
Default application extension order.
IApplicationExtension methods dummy implementation.
Prints the message in an ExitException.
Do the actual application work.
Adds a list of extensions (this.extensions) and methods to handle them. See ExtensibleClassMixin documentation for details.
Command line arguments passed to the application.
Short description of the application.
Application exit status code.
import ocean.util.app.Application; import ocean.io.Stdout; class MyApp : Application { this ( ) { super("myapp", "A test application"); } protected override void preRun ( Application app, istring[] args ) { if ( args.length < 4 ) { this.exit(1, "Too few arguments"); } } protected override int run ( istring[] args ) { Stdout.formatln("Application is running!"); return 0; } protected override void postRun ( Application app, istring[] args, int status ) { Stdout.formatln("Application returned {}", status); } } int main(istring[] args) { auto app = new MyApp; return app.main(args); }
As seen in the example, this class also provides a clean way to exit an application from anywhere in the program, the exit() method.
The main() method is the real only needed public API, and the one calling all the extension code. The real application call must be in the run() method, which is abstract, and mandatory to implement.
The full power and usefulness of this class comes from extensions though.
Extensible class to do all the common task needed for an application to run.
This class also implements its own extension interface, so it's easy to write an application using the hooks in extensions without having to write a separate extension. The order of this extension is 0, establishing a reference order for all the other extensions. Extensions that should be executed before the application hooks should have a negative order, while extensions that have to be executed after the application hooks should have a positive order value.
The common usage is to derive from Application and override the run() method. Optionally you can override the extensions methods too.