joptsimple
Class OptionSpecBuilder

java.lang.Object
  extended by joptsimple.AbstractOptionSpec<java.lang.Void>
      extended by joptsimple.NoArgumentOptionSpec
          extended by joptsimple.OptionSpecBuilder
All Implemented Interfaces:
OptionSpec<java.lang.Void>

public class OptionSpecBuilder
extends NoArgumentOptionSpec

Allows callers to specify whether a given option accepts arguments (required or optional).

Instances are returned from OptionParser.accepts(String) to allow the formation of parser directives as sentences in a "fluent interface" language. For example:


   OptionParser parser = new OptionParser();
   parser.accepts( "c" ).withRequiredArg().ofType( Integer.class );
 

If no methods are invoked on an instance of this class, then that instance's option will accept no argument.

Note that you should not use the fluent interface clauses in a way that would defeat the typing of option arguments:


   OptionParser parser = new OptionParser();
   ArgumentAcceptingOptionSpec<String> optionC =
       parser.accepts( "c" ).withRequiredArg();
   optionC.ofType( Integer.class );  // DON'T THROW AWAY THE TYPE!

   String value = parser.parse( "-c", "2" ).valueOf( optionC );  // ClassCastException
 

Version:
$Id: OptionSpecBuilder.java,v 1.16 2009/04/07 00:21:24 pholser Exp $
Author:
Paul Holser

Field Summary
private  OptionParser parser
           
 
Constructor Summary
OptionSpecBuilder(OptionParser parser, java.util.Collection<java.lang.String> options, java.lang.String description)
           
 
Method Summary
 ArgumentAcceptingOptionSpec<java.lang.String> withOptionalArg()
          Informs an option parser that this builder's option accepts an optional argument.
 ArgumentAcceptingOptionSpec<java.lang.String> withRequiredArg()
          Informs an option parser that this builder's option requires an argument.
 
Methods inherited from class joptsimple.NoArgumentOptionSpec
accept, acceptsArguments, convert, handleOption, requiresArgument
 
Methods inherited from class joptsimple.AbstractOptionSpec
description, equals, hashCode, options, toString, value, values
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

parser

private final OptionParser parser
Constructor Detail

OptionSpecBuilder

OptionSpecBuilder(OptionParser parser,
                  java.util.Collection<java.lang.String> options,
                  java.lang.String description)
Method Detail

withRequiredArg

public ArgumentAcceptingOptionSpec<java.lang.String> withRequiredArg()

Informs an option parser that this builder's option requires an argument.

Returns:
a specification for the option

withOptionalArg

public ArgumentAcceptingOptionSpec<java.lang.String> withOptionalArg()

Informs an option parser that this builder's option accepts an optional argument.

Returns:
a specification for the option