Home
Categories
Dictionary
Download
Project Details
Changes Log
Tutorials
FAQ
License

Command-line arguments file



The XML file specifying the arguments managed by a listener is returned by the CommandLineListener.getCommandLineConfiguration() method.

For example:
  public class MyMDI extends AbstractMDIApplication {

    public MyMDI(String[] args) {
      super("My MDI");
  ...
    }
   
    @Override
    public URL getCommandLineConfiguration() {
      return this.getClass().getResource("commandline.xml");
    }     
  }      

Structure of the arguments file

The file has a sequence of argument and argumentGroup elements:
  • An argument specifies an argument which is handled by the listener, and its associated type
  • An argumentGroup specifies a group of argument which is handled by the listener

argument element

An argument element specifies a command-line argument which is handled by the listener. It has the following attributes:
  • The key attribute (mandatory) is the argument name
  • The type attribute (optional) is the argument type. The handler will parse the argument to try to convert it to the appropriate type
The supported types are:
  • string (the default type) is for integer arguments
  • int is for integer arguments
  • short is for short arguments
  • char is for char arguments
  • float is for float arguments
  • boolean is for boolean arguments
  • url is for file paths arguments
  • properties is for an argument which point to a properties file which specifies other arguments
  • empty is for arguments which have no value, but will be only be used for their existance

argument class

The Argument class represents for a listener one argument managed by the listener and present. The Argument.getValue() method allows to return the value of the argument.

Only arguments which are present and have a not null value will be present, except for empty arguments which can have a null value.

argument states

It is possible to specify state values for arguments of type int, short, or char, in order to specify the value of the argument by a significant name. For example:
  <arguments>
     <argument key="align" type="int" >
        <states defaultState="1" >
           <state name="left" value="0" />
           <state name="right" value="1" />               
        </states>
     </argument>   
  </arguments>
And if we start the application with:
      java -jar MyMDI.jar -align=right
Then the arguments map will contain one align element with the value 1.

It is still possible in this case to specify directly the numeric value. If the default state is not specified, it will be considered equal to 0.

properties arguments

An argument which type is properties points to a properties file which specified (key, value) pairs for other arguments.

For example:
   <arguments>
      <argument key="sizeX" type="int" />
      <argument key="sizeY" type="int" />     
      <argument key="prop" type="properties" />    
   </arguments>
We can for example start the application with:
      java -jar MyMDI.jar -prop=properties.properties
If the properties.properties file has the following content:
  sizeX=800
  sizeY=300
Then the arguments map will contain two sizeX and sizeY elements.

argument example

For example for the following xml file specifies two int arguments:
   <arguments>
      <argument key="sizeX" type="int" />
      <argument key="sizeY" type="int" />     
   </arguments>
We can for example start the application with:
      java -jar MyMDI.jar -sizeX=800 -sizeY=300
Then the arguments map will contain two sizeX and sizeY elements.

If we start the application with:
      java -jar MyMDI.jar -sizeX=800
Then the arguments map will contain one sizeX element.

Second argument example

For example for the following xml file specifies an empty and an url arguments:
   <arguments>
      <argument key="import" type="empty" />
      <argument key="file" type="url" />     
   </arguments>
We can for example start the application with:
      java -jar MyMDI.jar -import -file=L:/my/file.xml
Then the arguments map will contain two import and file elements:
  • The import has a null value because it is an empty argument
  • The file has a File value because it is an url argument

argumentGroup element

An argumentGroup element specifies a group of command-line arguments which is handled by the listener. It has the following attributes:
  • The key attribute (mandatory) is the argument name
This element has several argument children which specify the arguments which are parts of the group. Each child element have the following attributes:
  • The key attribute (mandatory) is the argument name. This argument msut be present as a top-level argument in the xml file
  • The mandatory attribute is a boolean specifying if the argument is mandatory (by default the argument is optional)

An argumentGroup will only be present for a listener if:
  • All the mandatory arguments for the group are present
  • There is at least one argument for the group

argumentGroup example

For example for the following xml file specifies an empty and two url arguments:
   <arguments>
      <argument key="import" type="empty" />
      <argument key="file" type="url" />  
      <argument key="file2" type="url" />  
      <argumentGroup key="import">   
        <argument key="import" mandatory="true" />
        <argument key="file" mandatory="true"/>           
      </argumentGroup>
      <argumentGroup key="compare">   
        <argument key="compare" mandatory="true"/>
        <argument key="file" mandatory="true"/>  
        <argument key="file2" mandatory="true"/>         
      </argumentGroup>         
   </arguments>
We can for example start the application with:
      java -jar MyMDI.jar -import -file=L:/my/file.xml
In that case, there will be only one argumentGroup for the key import with two arguments:
  • import which is an empty argument
  • file which is an url argument
If we start the application with:
      java -jar MyMDI.jar -import -file=L:/my/file.xml -compare
In that case, we will still have only one argumentGroup for the key import with the same two arguments, because there is a compare argument but the file2 is absent.

Grammar of the arguments file

The XML file specifying the arguments has the following grammar: arguments Schema.

See also


Categories: commandline

Copyright 2006-2023 Herve Girod. All Rights Reserved. Documentation and source under the LGPL v2 and Apache 2.0 licences