Clad User Manual - How to Implement a Command Line Application: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 30: Line 30:


=Logging=
=Logging=
==Console Output==


<font color=red>
<font color=red>
TODO
TODO
</font>
</font>
==Debug Logging==
<font color=red>
TODO
</font>





Revision as of 17:53, 8 November 2016

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

Console Output

TODO


Debug Logging

TODO


SLF4J Binding

clad relies on SLF4J API, but does not enforce any binding. It is up to your application to define a binding among its dependencies. For more details see SLF4J - No StaticLoggerBinder.

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>
    <version>1.7.12</version>
</dependency>

TODO: Come up with a deterministic way to specify the slf4j-log4j12 version, in relation to the slf4j-api version used by clad.

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).