Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (C) 2011 Tatsuhiro Tsujikawa
   *
   * Permission is hereby granted, free of charge, to any person
   * obtaining a copy of this software and associated documentation
   * files (the "Software"), to deal in the Software without
   * restriction, including without limitation the rights to use, copy,
   * modify, merge, publish, distribute, sublicense, and/or sell copies
   * of the Software, and to permit persons to whom the Software is
  * furnished to do so, subject to the following conditions:
  *
  * The above copyright notice and this permission notice shall be
  * included in all copies or substantial portions of the Software.
  *
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  * SOFTWARE.
  */
 package net.sourceforge.argparse4j.inf;
 
 import java.util.List;

This interface provides a way to specify parameters to argument to be processed in ArgumentParser object.
 
 public interface Argument {

    

Sets the number of command line arguments that should be consumed.

Don't give this method '*', '+' or '?'. They are converted to int value and it is not what you expect. For these strings, use nargs(java.lang.String).

Parameters:
n A positive integer
Returns:
this
 
     Argument nargs(int n);

    

Sets the number of command line arguments that should be consumed.

This method takes one of following string: "*", "+" and "?". If "*" is given, All command line arguments present are gathered into a java.util.List. If "+" is given, just like "*", all command line arguments present are gathered into a java.util.List. Additionally, an error message will be generated if there wasn't at least one command line argument present. If "?" is given, one argument will be consumed from the command line if possible, and produced as a single item. If no command line argument is present, the value from setDefault(java.lang.Object) will be produced. Note that for optional arguments, there is an additional case - the option string is present but not followed by a command line argument. In this case the value from setConst(java.lang.Object) will be produced.

Parameters:
n "*", "+" or "?"
Returns:
this
 
     Argument nargs(String n);

    

Sets constant values that are not read from the command line but are required for the various actions.

The const value defauls to null.

Parameters:
value The const value
Returns:
this
 
     Argument setConst(Object value);

    

Sets list of constant values that are not read from the command line but are required for the various actions.

The given values will be converted to java.util.List. The const value defauls to null. If you want to set non-List item, use setConst(java.lang.Object).

Parameters:
values The const values
Returns:
this
    <E> Argument setConst(E... values);

    

Sets value which should be used if the command line argument is not present.

The default value defaults to null.

Parameters:
value The default value
Returns:
this
    Argument setDefault(Object value);

    

Sets list of values which should be used if the command line argument is not present.

The default value defaults to null. The given values will be converted to java.util.List. If you want to set non-List item, use setDefault(java.lang.Object).

Parameters:
values The default values
Returns:
this
    <E> Argument setDefault(E... values);

    

Sets special value to control default value handling.

Currently, only FeatureControl.SUPPRESS is available. If it is given, default value is not add as a attribute.

Parameters:
ctrl The special value to control default value handling.
Returns:
this
    Argument setDefault(FeatureControl ctrl);

    

Sets the type which the command line argument should be converted to.

By default, type is String, which means no conversion is made. The type must have a constructor which takes one String argument.

Parameters:
type The type which the command line argument should be converted to.
Returns:
this
    <T> Argument type(Class<T> type);

    

Sets ArgumentType object which converts command line argument to appropriate type.

This would be useful if you need to convert the command line argument into a type which does not have a constructor with one String argument.

Parameters:
type The ArgumentType object
Returns:
this
    <T> Argument type(ArgumentType<T> type);

    

If true is given, this optional argument must be specified in command line otherwise error will be issued.

The default value is false. This object is a positional argument, this property is ignored.

Parameters:
required true or false
Returns:
this
    Argument required(boolean required);

    
Sets the action to be taken when this argument is encountered at the command line.

Parameters:
action ArgumentAction object
Returns:
this
    Argument action(ArgumentAction action);

    

Sets ArgumentChoice object which inspects value so that it fulfills its criteria.

This method is useful if more complex inspection is necessary than basic choices(java.lang.Object[]).

Parameters:
choice ArgumentChoice object.
Returns:
this
    Argument choices(ArgumentChoice choice);

    
Sets a collection of the allowable values for the argument.

Parameters:
values A collection of the allowable values
Returns:
this
    <E> Argument choices(Collection<E> values);

    
Sets a collection of the allowable values for the argument.

Parameters:
values A collection of the allowable values
Returns:
this
    <E> Argument choices(E... values);

    

The name of the attribute to be added.

The default value is For positional arguments, The default value is normally supplied as the first argument to ArgumentParser.parseArgs(java.lang.String[]). For optional arguments, ArgumentParser generates the default value of dest by taking the first long option string and stripping away the initial -- string. If no long option strings were supplied, dest will be derived from the first short option string by stripping the initial - character. Any internal - characters will be converted to _.

Parameters:
dest The name of the attribute to be added
Returns:
this
    Argument dest(String dest);

    
Set the name for the argument in usage messages.

Parameters:
metavar The name for the argument in usage messages
Returns:
this
    Argument metavar(String... metavar);

    
Sets the brief description of what the argument does.

Parameters:
help The brief description of what the argument does
Returns:
this
    Argument help(String help);

    

Sets special value to control help message handling.

Currently, only FeatureControl.SUPPRESS is available. If it is given, the help entry for this option is not displayed in the help message.

Parameters:
ctrl The special value to control help message handling.
Returns:
this
    Argument help(FeatureControl ctrl);

    

Returns textual representation of the argument name.

For optional arguments, this method returns the first argument given in ArgumentParser.addArgument(java.lang.String[]). For positional arguments, this method returns the flags joined with "/", e.g. -f/--foo.

Returns:
The textual representation of the argument name.
    // Getter methods

    
Returns dest value.

Returns:
The dest value
    String getDest();

    
Returns const value.

Returns:
The const value
    Object getConst();

    
Returns default value.

Returns:
The default value
    Object getDefault();

    
Returns default control.

Returns:
The default control
Returns help control.

Returns:
The help control
New to GrepCode? Check out our FAQ X