Clad User Manual - How to Implement a Command Line Application: Difference between revisions
(Created page with "=Internal= * clad User Manual") |
No edit summary |
||
Line 2: | Line 2: | ||
* [[Clad_User_Manual#Subjects|clad User Manual]] | * [[Clad_User_Manual#Subjects|clad User Manual]] | ||
=Overview= | |||
=Declare the Maven Dependency= | |||
<pre> | |||
<dependency> | |||
<groupId>io.novaordis.clad</groupId> | |||
<artifactId>novaordis-clad</artifactId> | |||
<version>...</version> | |||
</dependency> | |||
</pre> | |||
=Provide an ApplicationRuntime Implementation= | |||
Extend <tt>[https://github.com/NovaOrdis/clad/blob/master/src/main/java/io/novaordis/clad/application/ApplicationRuntimeBase.java ApplicationRuntimeBase]</tt>, into a "clad" sub-package. This is the recommended approach. If you need more flexibility, you can implement <tt>[https://github.com/NovaOrdis/clad/blob/master/src/main/java/io/novaordis/clad/application/ApplicationRuntime.java ApplicationRuntime]</tt> interface. | |||
The application runtime functionality is related to the following aspects: | |||
===Default Command=== | |||
To provide a default command, implement <tt>public String getDefaultCommandName()</tt>. For more details on the default command, see "[[Clad_User_Manual_-_Concepts#Default_Command|Default Command]]" section. | |||
===Global Options=== | |||
For more details on the default command, see "[[Clad_User_Manual_-_Concepts#Global_Options|Global Options]]" section. | |||
==Logging== | |||
<font color=red> | |||
TODO | |||
</font> | |||
==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 | |||
<font color=red> | |||
Package the application runtime implementation class and the commands in a JAR (or place them in a directory). | |||
Set “<tt>application.name</tt>” as a system property. If the application runtime implementation class is <tt>BlueApplicationRuntime</tt>, the application.name must be “blue”. | |||
Make sure the JAR or the directory is first on the class path (otherwise other <tt><your-command-name>Command.class</tt>, if exist, will be instantiated first). | |||
</font> |
Revision as of 17:36, 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. 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:
Default Command
To provide a default command, implement public String getDefaultCommandName(). For more details on the default command, see "Default Command" section.
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).