Damian Eads
# A short option. myprogram -s
# Several short options. myprogram -abcdef # This is equivalent. myprogram -a -b -c -d -e -fValues may not be supplied when options are invoked as a short option list.
myprogram -a "hello" -bcd -e=15
myprogram --myoption
myprogram --longoption1,longoption2,longoption3
myprogram --longoption=value -s=value
myprogram --longoption value
# Let's set a to true and b to false myprogram -a+ -b- --longa+ --longb-
# The following will work. myprogram -s "Hello Sir," --long "How do you do?" # The following will cause errors. myprogram -s=Hello Sir, --long How do you do?
# Let's set each option to true. myprogram -a true -b yes -c on -d activated -e active # Let's set each option to false. myprogram -a false -b no -c off -d "not activated" -e inactive
myprogram --myarrayoption=value1,value2 myprogram --myarrayoption value1,value2,value3 myprogram --mystringarrayoption="value one","value two","value three" # The following, however will cause errors. myprogram --myarrayoption value1, value2, value3
myprogram :module1: --myoption 5 :module2: --myoption 8
server-manager :http: --timeout=15 :ftp: --timeout=30 :pop: --timeout=20In the example above, three separate options were invoked from three separate modules.
Options options = new Options();In theory, this is all that needs to be done to get started. The default constructor will provide the repository with a default program name and version information. To demonstrate this simply do a --help.
cookies@crazymonster$ java MyProgram --help java program @optionfile :module: OPTIONS ... :module: OPTIONS Use --menu to invoke the interactive built-in menu. Option Name Type Description -h, --help <NOTIFY> Displays help for each option. -m, --menu <NOTIFY> Displays the built-in interactive menu. -v, --version <NOTIFY> Displays version information.
Options options = new Options( "gnu-food" );Whenever ritopt displays program information it will use the name it is initialized.
options.setVersion( "gnu-food 0.2" );When the --version option is specified, version information is displayed.
cookies@crazymonster$ gnu-food --version gnu-food 0.2 cookies@crazymonster$
StringOption name = new StringOption( "Fred" ); IntOption age = new IntOption( 19 ); FloatOption bankBalance = new FloatOption( 100.15f ); BooleanOption married = new BooleanOption( false );
// Let's specify both a short and long option. options.register( "name", 'n', name ); // or just a long option. options.register( "age", age ); // or just a short option. options.register( 'm', married ); // How 'bout a description? options.register( "bank-balance", 'b', "Bank Balance", bankBalance );
String leftoverArgs[] = options.process( args );
import gnu.dtools.ritopt.*; public class RegisterPersonal { private static StringOption name = new StringOption( "Fred" ); private static IntOption age = new IntOption( 19 ); private static FloatOption bankBalance = new FloatOption( 100.15f ); private static BooleanOption married = new BooleanOption( false ); public static void main( String args[] ) { // Create an options repository. Options options = new Options( "RegisterPersonal" ); // Set the version. options.setVersion( "RegisterPersonal Version 1.0" ); // Register the options. options.register( "name", 'n', name ); options.register( "age", age ); options.register( 'm', married ); options.register( "bank-balance", 'b', "Bank Balance", bankBalance ); // Process the command line and ignore the leftover arguments. options.process( args ); // Print out the results. System.out.println( "Name: " + name.getValue() ); System.out.println( "Age: " + age.getValue() ); System.out.println( "Married: " + married.getValue() ); System.out.println( "BankBalance: " + bankBalance.getValue() ); } }
Let's compile the program, create a script, and run it a few times.
nomad@nomansland$ javac -classpath ritopt-x.x.x-bin.jar:. RegisterPersonal.java nomad@nomansland$ # Let's create a script nomad@nomansland$ echo 'java -cp ritopt-x.x.x-bin:'${PWD}' RegisterPersonal' $* \ > RegisterPersonal nomad@nomansland$ chmod +x RegisterPersonal nomad@nomansland$ ./RegisterPersonal Name: Fred Age: 19 Married: false BankBalance: 100.15 nomad@nomansland$ ./RegisterPersonal --help RegisterPersonal @optionfile :module: OPTIONS ... :module: OPTIONS Use --menu to invoke the interactive built-in menu. Option Name Type Description -h, --help <NOTIFY> Displays help for each option. -m, --menu <NOTIFY> Displays the built-in interactive menu. --age <INTEGER> No description given -v, --version <NOTIFY> Displays version information. -b, --bank-bala <FLOAT> Bank Balance -n, --name <STRING> No description given -m <BOOLEAN> No description given nomad@nomansland$ ./RegisterPersonal --version RegisterPersonal Version 1.0 nomad@nomansland$ # Let's set the name nomad@nomansland$ ./RegisterPersonal --name="Jonathan Doe" --age=20 Name: Jonathan Doe Age: 19 Married: false BankBalance: 100.15 nomad@nomansland$ ./RegisterPersonal --name="Jonathan Doe" --age=20 -m Name: Jonathan Doe Age: 19 Married: false BankBalance: 100.15 nomad@nomansland$ ./RegisterPersonal --married Error: Option --married does not exist in module 'General'. Name: Jonathan Doe Age: 19 Married: false BankBalance: 100.15
ritopt is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
ritopt is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with ritopt; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
This document was generated using the LaTeX2HTML translator Version 99.2beta6 (1.42)
Copyright © 1993, 1994, 1995, 1996,
Nikos Drakos,
Computer Based Learning Unit, University of Leeds.
Copyright © 1997, 1998, 1999,
Ross Moore,
Mathematics Department, Macquarie University, Sydney.
The command line arguments were:
latex2html -dir /home/users/g/go/googolminex/ritopt_l/htdocs/tut tutorial.tex -split 3
The translation was initiated by Damian Eads on 2001-10-24