Clad User Manual - How to Implement a Command Line Application

From NovaOrdis Knowledge Base
Revision as of 17:38, 8 November 2016 by Ovidiu (talk | contribs)
Jump to navigation Jump to search

Internal

Overview

Declare the Maven Dependency

<dependency>
    <groupId>io.novaordis.clad</groupId>
    <artifactId>novaordis-clad</artifactId>
    <version>...</version>
</dependency>

Provide an ApplicationRuntime Implementation

Extend ApplicationRuntimeBase, into a "clad" sub-package of your project. This is the recommended approach. If you need more flexibility, you can implement ApplicationRuntime interface.

The application runtime functionality is related to the following aspects:

Specify a Default Command

To provide a default command, implement public String getDefaultCommandName(). For more details on the default command, see "Default Command" section.

Define Global Options

For more details on the default command, see "Global Options" section.

Logging

TODO

Wrapper

java -cp ... io.novaordis.clad.CommandLineApplication

Application Name

The application name should be provided as a system property argument to java, in the wrapper:


-Dapplication.name=Release



Package the application runtime implementation class and the commands in a JAR (or place them in a directory).

Set “application.name” as a system property. If the application runtime implementation class is BlueApplicationRuntime, the application.name must be “blue”.

Make sure the JAR or the directory is first on the class path (otherwise other <your-command-name>Command.class, if exist, will be instantiated first).