Clad User Manual: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
 
(44 intermediate revisions by the same user not shown)
Line 7: Line 7:
The framework scans the command line looking for the first argument that can be mapped to a command.  
The framework scans the command line looking for the first argument that can be mapped to a command.  


The mapping process involves scanning the classpath and looking for classes implementing the [https://github.com/NovaOrdis/clad/blob/master/src/main/java/io/novaordis/clad/command/Command.java Command interface]. The current version does not introspect all classes, but just those whose simple class name match the following pattern: <tt><commandName>Command</tt>.  
The mapping process involves scanning the classpath and looking for classes implementing the [https://github.com/NovaOrdis/clad/blob/master/src/main/java/io/novaordis/clad/command/Command.java Command interface]. The current version does not introspect all classes, but just those whose simple class name match the following pattern: <tt><commandName>Command</tt>. All arguments between the wrapper name and the command name are interpreted as global options. All arguments following the command name are interpreted as command options.
 
All arguments between the wrapper name and the command name are interpreted as global options.
 
All arguments following the command name are interpreted as command options.


<pre>
<pre>
 
wrapper [global-options] command [command-options]
  wrapper [global-options] command [command-options]
 
</pre>
 
=Options=
 
The options use the GNU command line convention:
 
<pre>
 
-o <value> | --option=<value>
 
</pre>
</pre>


=Configuration File=
=Subjects=
 
Each command line option has a configuration file correspondent. Command line value takes precedence over the configuration file value.
 
=Implementing a Command=
 
Implement the [https://github.com/NovaOrdis/clad/blob/master/src/main/java/io/novaordis/clad/command/Command.java Command] interface.
 
The implementation class must be named <tt><command-name>Command</tt>.


Example: <tt>PrintCommand</tt> will be matched to the "<tt>print</tt>" command. <tt>BusinessScenarioCommand</tt> will be matched to the "<tt>business-scenario</tt>" command.
<blockquote style="background-color: #f9f9f9; border: solid thin lightgrey;">
 
:[[clad User Manual - Concepts|Concepts]]
==Relationship between Command and ApplicationRuntime==
:[[clad User Manual - How to Implement a Command Line Application|How to Implement a Command Line Application]]
 
</blockquote>
If a specific command does not need an application runtime instance (thus the framework is not required to instantiate an application runtime for it), the <tt>Command.needsRuntime()</tt> implementation must return <tt>false</tt>. By default <tt>CommandBase.needsRuntime()</tt> returns <tt>true</tt>.
 
==In-Line Command Help==
 
If a text file named <tt><command-name>.txt</tt> is placed in the same package as the command implementation class, the framework will send the content of the file to <tt>stdout</tt> when in-line command help is requested:
 
<pre>
    <wrapper> --help <command>
</pre>

Latest revision as of 18:17, 8 November 2016

Internal

Overview

The framework scans the command line looking for the first argument that can be mapped to a command.

The mapping process involves scanning the classpath and looking for classes implementing the Command interface. The current version does not introspect all classes, but just those whose simple class name match the following pattern: <commandName>Command. All arguments between the wrapper name and the command name are interpreted as global options. All arguments following the command name are interpreted as command options.

wrapper [global-options] command [command-options]

Subjects

Concepts
How to Implement a Command Line Application