CliApp

CliApp class

Constructors

this
this(istring name, istring desc, VersionInfo ver, OptionalSettings settings)

This constructor only sets up the internal state of the class, but does not call any extension or user code.

Members

Aliases

Arguments
alias Arguments = ocean.text.Arguments.Arguments
Undocumented in source.

Functions

preValidateArgs
void preValidateArgs(IApplication app, Arguments args)
Undocumented in source. Be warned that the author may not have intended to support it.
processArgs
void processArgs(IApplication app, Arguments args)
Undocumented in source. Be warned that the author may not have intended to support it.
run
int run(istring[] args)

Run implementation that forwards to the abstract run(Arguments, ConfigParser).

run
int run(Arguments args)

This method must be implemented by subclasses to do the actual application work.

setupArgs
void setupArgs(IApplication app, Arguments args)

IArgumentsExtExtension methods dummy implementation.

validateArgs
cstring validateArgs(IApplication app, Arguments args)
Undocumented in source. Be warned that the author may not have intended to support it.

Structs

OptionalSettings
struct OptionalSettings

Struct containing optional constructor arguments. There are enough of these that handling them as default arguments to the ctor is cumbersome.

Variables

args
Arguments args;

Command line arguments used by the application.

args_ext
ArgumentsExt args_ext;

Command line arguments extension used by the application.

task_ext
TaskExt task_ext;

Extension to start run method inside a task.

ver
VersionInfo ver;

Version information.

ver_ext
VersionArgsExt ver_ext;

Version information extension.

Inherited Members

From Application

__anonymous
mixin ExtensibleClassMixin!(IApplicationExtension)

Adds a list of extensions (this.extensions) and methods to handle them. See ExtensibleClassMixin documentation for details.

Application
alias Application = .Application

Alias of Application, for use by sub-classes without needing to import ocean.util.app.Application.

desc
istring desc;

Short description of the application.

args
istring[] args;

Command line arguments passed to the application.

status
int status;

Application exit status code.

name
istring name()
exit
void exit(int status, istring msg)

Exit cleanly from the application.

main
int main(istring[] args)

Runs the application.

printExitException
void printExitException(ExitException e)

Prints the message in an ExitException.

run
int run(istring[] args)

Do the actual application work.

order
int order()

Default application extension order.

preRun
void preRun(IApplication app, istring[] args)

IApplicationExtension methods dummy implementation.

postRun
void postRun(IApplication app, istring[] args, int status)
Undocumented in source. Be warned that the author may not have intended to support it.
atExit
void atExit(IApplication app, istring[] args, int status, ExitException exception)
Undocumented in source. Be warned that the author may not have intended to support it.
onExitException
ExitException onExitException(IApplication app, istring[] args, ExitException exception)
Undocumented in source. Be warned that the author may not have intended to support it.

From IArgumentsExtExtension

setupArgs
void setupArgs(IApplication app, Arguments args)

Function executed when command line arguments are set up (before parsing).

preValidateArgs
void preValidateArgs(IApplication app, Arguments args)

Function executed after parsing of command line args (whether the basic parsing failed or succeeded) but before the call to validateArgs().

validateArgs
cstring validateArgs(IApplication app, Arguments args)

Function executed after parsing the command line arguments.

processArgs
void processArgs(IApplication app, Arguments args)

Function executed after (successfully) validating the command line arguments.

Examples

1 /***************************************************************************
2 
3     Example CLI application class.
4 
5 ***************************************************************************/
6 
7 class MyApp : CliApp
8 {
9     this ( )
10     {
11         // The name of your app and a short description of what it does.
12         istring name = "my_app";
13         istring desc = "Dummy app for unittest.";
14 
15         // The version info for your app. Normally you get this by importing
16         // Version and passing the AA which contains the version info
17         // (called Version) to CliApp's constructor.
18         auto ver = VersionInfo.init;
19 
20         // You may also pass an instance of OptionalSettings to CliApp's
21         // constructor, to specify non-mandatory options. In this example,
22         // we specify the help text.
23         CliApp.OptionalSettings settings;
24         settings.help = "Actually, this program does nothing. Sorry!";
25 
26         // Call the super class' ctor.
27         super(name, desc, ver, settings);
28     }
29 
30     // Called after arguments and config file parsing.
31     override protected int run ( Arguments args )
32     {
33         // Application main logic.
34 
35         return 0; // return code to OS
36     }
37 }
38 
39 /***************************************************************************
40 
41     Your application's main() function should look something like this.
42     (This function is not called here as we don't want to actually run the
43     application in this unittest.)
44 
45 ***************************************************************************/
46 
47 int main ( istring[] cl_args )
48 {
49     // Instantiate an instance of your app class.
50     auto my_app = new MyApp;
51 
52     // Pass the raw command line arguments to its main function.
53     auto ret = my_app.main(cl_args);
54 
55     // Return ret to the OS.
56     return ret;
57 }

Meta