Welcome To GetOpt Generator
GetOpt Generator is a Java tool that generates a command-line argument parser from an XML file.
Both a 'parser' and 'config' class are generated, which allows your program to either be launched from the command-line or programmatically configured and executed from another Java application.
GetOpt Generator is Self-Hosting meaning it uses itself to generate its command-line parser.
Configuration
You can look at GetOpt.xml, the XML used by GetOpt to generate its own command-line parser, for an example of what the XML configuration file should look like.
Basically each option gets:
name
Long name of the option. Separate logical words with "_" (i.e. long_opt)
short
Short (1 char) alias for the option
type
One of:
- boolean
- integer
- string
- input-file (verifies that file exists)
- input-dir (verifies that dir exists)
- output-file (treated as string for now)
- output-dir (treated as string for now)
required
yes | no
default
A default value appropriate for the type
Downloading
If you are interested in this project, and have Java (5.0+) installed, why not download it and give it a try?
On the download page, you'll find zip and tar.gz versions of both the binary and source distributions.
The distribution (currently) contains all required .jar files necessary to run, so it should be relatively simple to try it out.
Running GetOpt
Calling GetOpt with --help generates the following output
options for GetOpt :
[ --help | -? ]
( --xmlFile | -x ) xml_file
( --javaDir | -j ) java_dir
( --exeClass | -e ) exe_class
( --mainClass | -m ) main_class
( --configClass | -c ) config_class
NOTE: Options in brackets '[]' are optional.
All camel-case long opts can be represented using lowercase,
as well as with '-' or '_' seperating the camel-cased words
(i.e. --longOpt | --longopt | --long_opt | --long-opt)
xml_file
The XML file containing the configuration
main_class
The fully qualified name (package+class) of the generated class that will parse the command line (i.e. contains the main() method).
config_class
The fully qualified name (package_class) of the generated class that will store the config information.
java_dir
The base output directory (i.e. your src directory). The generated files will be stored in /java/dir/package/path/ClassName.java
exe_class
The Java class that the generated command-line parser should call after parsing the command line.
The exe class is expected to contain a constructor that accepts a config_class instance.
The exe class is expected to contain an execute() method, which will be called by the command-line parser.
It is the responsibility of the exe class to validate the parsed config, but the config_class is generated with a validate() function which does the heavy lifting.
Comments, Problems, Bug Reports
If you have any comments, or need help, feel free to Email Me.
Any feedback would be appreciated.
You are also invited to register a Trac account. Registration is free and registered users can contribute to Trac tickets as well as create new tickets.
To Do
- Impliment minOccurs/maxOccurs options (started)
- Express/Enforce inter-option relationsips
- Support multiple occurrences of an option (i.e. 'list'
- Support name-value pairs (i.e. 'map' type)
- Named operands
- Create a better '--help' screen
Looking for the original Trac Welcome Page?