App

Tests

version(unittest)
class App : Application {}

Constructors

this
this()
Undocumented in source.

Members

Functions

run
int run(istring[] args)
Undocumented in source. Be warned that the author may not have intended to support it.

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.

Examples

Test --help can be used even when required arguments are not specified

auto stdout_dev = new MemoryDevice;
auto stdout = new TextOutput(stdout_dev);

auto stderr_dev = new MemoryDevice;
auto stderr = new TextOutput(stderr_dev);

istring usage_text = "test: usage";
istring help_text = "test: help";
auto arg = new ArgumentsExt("test-name", "test-desc", usage_text, help_text,
        stdout, stderr);
arg.args("--required").params(1).required;

auto app = new App;

try
{
    arg.preRun(app, ["./app", "--help"]);
    test(false, "An ExitException should have been thrown");
}
catch (ExitException e)
{
    // Status should be 0 (success)
    test!("==")(e.status, 0);
    // No errors should be printed
    test!("==")(stderr_dev.bufferSize, 0);
    // Help should be printed to stdout
    auto s = cast(mstring) stdout_dev.peek();
    test(s.length > 0,
            "Stdout should have some help message but it's empty");
    test(s.find(arg.args.short_desc) < s.length,
         "No application description found in help message:\n" ~ s);
    test(s.find(usage_text) < s.length,
         "No usage text found in help message:\n" ~ s);
    test(s.find(help_text) < s.length,
         "No help text found in help message:\n" ~ s);
    test(s.find("--help"[]) < s.length,
         "--help should be found in help message:\n" ~ s);
}

Meta