FileDocCategorySizeDatePackage
SomeApp.javaAPI DocExample2959Wed May 18 09:38:58 BST 2005com.discursive.jccook.cmdline

SomeApp

public class SomeApp extends Object

Fields Summary
private static final String
USAGE
private static final String
HEADER
private static final String
FOOTER
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)


           
    	
	    // Create a Parser
        CommandLineParser parser = new BasicParser();
        Options options = new Options();
        options.addOption("h", "help", false, "Print this usage information");
        options.addOption("v", "verbose", false, "Print out VERBOSE information" );

        OptionGroup optionGroup = new OptionGroup(); 
        optionGroup.addOption( OptionBuilder.hasArg(true).withArgName("file")
        		                            .withLongOpt("file").create('f") );
        optionGroup.addOption( OptionBuilder.hasArg(true).withArgName("email")
        									.withLongOpt("email").create('m") );
        options.addOptionGroup( optionGroup );

   	    // Parse the program arguments
	    try {
            CommandLine commandLine = parser.parse( options, args );

            if( commandLine.hasOption('h") ) {
                printUsage( options );
                System.exit(0);
            }
	
   	        // ... do important stuff ...
        } catch( Exception e ) {
            System.out.println( "You provided bad program arguments!" );
            printUsage( options );
            System.exit(1);
        }
    
private static voidprintUsage(org.apache.commons.cli.Options options)

        HelpFormatter helpFormatter = new HelpFormatter();
        helpFormatter.setWidth( 80 );
        helpFormatter.printHelp( USAGE, HEADER, options, FOOTER );