The very first thing you need to do when implementing the command-line processor is to create an instance of Argument.
Argument is written as a class called CmdLine
. And it has an interface for it called ICmdLine
. The interface has all of the methods you will need to interact with your command-line options. Create an instance and optionally assign it to a variable.
ICmdLine arguments = CmdLine.create("Your parser definition goes here");
create("")
is a static convenience method for the most popular use of Argument. It makes some realistic assumptions in order to hide some of the details.
There are several more detailed ways to create an instance of Argument.
You can assign a name to this instance of Argument. The name is used when the help (-?
) is requested. The default for this field is "[argument]
" if you don't specify it.
ICmdLine arguments = new CmdLine( "MyProgram" );
You can specify a help message. This will also appear in the help display (-?
).
ICmdLine arguments = new CmdLine( "MyProgram", "MyProgram will process your command-line parameters." );
Optionally, you can specify the two characters that are used during the parsing of the command-line. In Unix types of systems it is command to use dashes ('-'
) for the command prefix. While in Windows it is more common to use slashes ('/'
). The default that Argument uses is dashes unless you change it when creating the Argument instance.
The second character is the "not", or "reset" character. There really is no default for this in Unix. In Windows it is the exclamation-point ('!'
), much like it is in a lot of languages for negation. The default for Argument is '!'
. This will probably not frequently be used on the command-line. But it does provide an important feature that may be needed on occasion.
ICmdLine arguments = new CmdLine( "MyProgram", "MyProgram will process your command-line parameters.", '-', '!' );
You can leave the help message off and just specify the other three parameters.
<pre name="code" class="java:html:nocontrols">ICmdLine arguments = new CmdLine( "MyProgram", '-', '!' );