jargs.gnu
Class CommandLineApplicationParser<E>

java.lang.Object
  extended by jargs.gnu.CommandLineApplicationParser<E>
Type Parameters:
E - Type of the command-line application

public class CommandLineApplicationParser<E>
extends java.lang.Object

Starting-point for the annotation-based command-line option parsing.

Creates a CommandLineParser based on the annotations in the command-line application class.

 Example:
 
 @CommandLineApplication(appName = "Application", enableHelp = true, showUsageOnExeption = true)
 public class Application {
 
   // -s,--show: show GUI
   @CommandLineOption(longForm="show", shortForm="s", description="show GUI")
   private boolean show; // default: false
 
   // --text; allowed values [Lorem ipsum, foo]
   @CommandLineOption()
   @CommandLineValidator({ "Lorem ipsum", "foo" })
   private String text; // default: "Lorem ipsum"
 
   // --count
   @CommandLineOption()
   private Integer count; // default: null
 
   // --f; interval [-10.3, 2.6]
   @CommandLineOption()
   @CommandLineValidator(min = "-10.3f", max = "2.6f")
   private float f = 1.23f; // default: 1.23f
        
   private Application() {
     // required default constructor, 
     // can also be used to initialize fields
     text = "Lorem ipsum";
   }
 
   public void start() {
     if (show) {
       doSomethingWithGUI();
     } else {
       doSomething();
     }
   }
  
   public static void main(String[] args) {
     CommandLineApplicationParser<Application> clap = CommandLineApplicationParser.of(Application.class);
     Application app = clap.parse(args);
     app.start();
   }
 }
 

Author:
Philipp Eichhorn

Method Summary
 java.io.PrintStream getPrintStream()
          Returns the PrintStream used for CommandLineParser.printUsage().
 java.lang.String[] getRemainingArgs()
           
 boolean helpRequested()
           
static
<T> CommandLineApplicationParser<T>
of(java.lang.Class<T> annotatedObjectType)
           
static
<T> CommandLineApplicationParser<T>
of(java.lang.Class<T> annotatedObjectType, java.util.Locale locale)
           
static
<T> CommandLineApplicationParser<T>
of(T annotatedObject)
           
static
<T> CommandLineApplicationParser<T>
of(T annotatedObject, java.util.Locale locale)
           
 E parse(java.lang.String[] args)
           
 void setPrintStream(java.io.PrintStream out)
          Sets the PrintStream used for CommandLineParser.printUsage().
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

parse

public E parse(java.lang.String[] args)
        throws IllegalOptionValueException,
               UnknownOptionException
Throws:
IllegalOptionValueException
UnknownOptionException

helpRequested

public boolean helpRequested()

getRemainingArgs

public java.lang.String[] getRemainingArgs()
Returns:
The arguments no option was specified for.

setPrintStream

public void setPrintStream(java.io.PrintStream out)
Sets the PrintStream used for CommandLineParser.printUsage().


getPrintStream

public java.io.PrintStream getPrintStream()
Returns the PrintStream used for CommandLineParser.printUsage().


of

public static <T> CommandLineApplicationParser<T> of(T annotatedObject)
                                          throws java.lang.IllegalArgumentException
Throws:
java.lang.IllegalArgumentException

of

public static <T> CommandLineApplicationParser<T> of(T annotatedObject,
                                                     java.util.Locale locale)
                                          throws java.lang.IllegalArgumentException
Throws:
java.lang.IllegalArgumentException

of

public static <T> CommandLineApplicationParser<T> of(java.lang.Class<T> annotatedObjectType)
                                          throws java.lang.IllegalArgumentException
Throws:
java.lang.IllegalArgumentException

of

public static <T> CommandLineApplicationParser<T> of(java.lang.Class<T> annotatedObjectType,
                                                     java.util.Locale locale)
                                          throws java.lang.IllegalArgumentException
Throws:
java.lang.IllegalArgumentException