org.xerial.util.cui
Class OptionGroup<OptionID extends Comparable>

java.lang.Object
  extended by org.xerial.util.cui.OptionGroup<OptionID>

public class OptionGroup<OptionID extends Comparable>
extends Object

OptionGroup creates a bundle of options By setting some OptionGroup as exclusive, you can prevent multiple exclusive OptionGroups will be activated at the same time.

usage

    enum Opt { "cui", "gui" }
    OptionGroup<Opt> cuiGroup = new OptionGroup<Opt>("cui", true);
    cuiGroup.addOption(Opt.cui, "c", "cui", "CUI mode");
    OptionGroup<Opt> guiGroup = new OptionGroup<Opt>("gui", true);
    guiGroup.addOption(Opt.gui, "g", "gui", "GUI mode");
    
    OptionParser<Opt> parser = new OptionParser<Opt>();
    parser.addOptionGroup(cuiGroup);
    parser.addOptionGroup(guiGroup);
    
    parser.parse(new String[] {"--cui", "--gui" }); // throws OptionParserException
    
 

Author:
leo

Constructor Summary
OptionGroup(String groupName)
           
OptionGroup(String groupName, boolean isExclusive)
          Creates an option group
 
Method Summary
 void activate()
           
protected  void activateParentGroup()
           
 void addOption(OptionID optionID, String shortOptionName, String longOptionName, String description)
          Adds an option to this option group
 void addOption(OptionID optionID, String shortOptionName, String longOptionName, String description, boolean presetValue)
          Adds an option to this option group
 void addOption(OptionID optionID, String shortOptionName, String longOptionName, String description, boolean presetValue, OptionHandler<OptionID> handler)
          Adds an option to this option group
 void addOption(OptionID optionID, String shortOptionName, String longOptionName, String description, OptionHandler<OptionID> handler)
          Adds an option to this option group
 void addOptionGroup(OptionGroup<OptionID> optionGroup)
           
 void addOptionHandler(OptionID optionID, OptionHandler<OptionID> handler)
           
 void addOptionWithArgment(OptionID optionID, String shortOptionName, String longOptionName, String argumentName, String description)
          Adds an option to this option group
 void addOptionWithArgment(OptionID optionID, String shortOptionName, String longOptionName, String argumentName, String description, OptionHandler<OptionID> handler)
          Adds an option to this option group
 void addOptionWithArgment(OptionID optionID, String shortOptionName, String longOptionName, String argumentName, String description, String defaultValue)
          Adds an option to this option group
protected  void collectOptionDescriptions(org.xerial.util.cui.OptionDescriptionContainer container)
           
protected  void collectOptionID(List<OptionID> optionIDList)
           
protected  Option<OptionID> findByLongOptionName(String longOption)
           
protected  Option<OptionID> findByShortOptionName(String shortOption)
           
protected  Option<OptionID> findOption(OptionID optionID)
           
 String getGroupName()
           
 OptionHandler<OptionID> getOptionHandler(OptionID optionID)
          Finds the option handler of the specified optionID.
protected  OptionGroup<OptionID> getParent()
           
 void handle(String[] args, int argIndex)
           
 boolean isActive()
           
protected  void setParent(OptionGroup<OptionID> parentGroup)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OptionGroup

public OptionGroup(String groupName)

OptionGroup

public OptionGroup(String groupName,
                   boolean isExclusive)
Creates an option group

Parameters:
groupName - the group name
isExclusive - true when you forbid the activation of other option groups, which belong to the same level with this option group
Method Detail

addOption

public void addOption(OptionID optionID,
                      String shortOptionName,
                      String longOptionName,
                      String description)
Adds an option to this option group

Parameters:
optionID - the option ID
shortOptionName - the short option name. If you specified "h" as the argument, "-h" can be used as a command line option
longOptionName - the long option name. If you specified "help" as the argument, "--help" can be used as a command line option
description - the description of this option

addOption

public void addOption(OptionID optionID,
                      String shortOptionName,
                      String longOptionName,
                      String description,
                      boolean presetValue)
Adds an option to this option group

Parameters:
optionID - the option ID
shortOptionName - the short option name. If you specified "h" as the argument, "-h" can be used as a command line option
longOptionName - the long option name. If you specified "help" as the argument, "--help" can be used as a command line option
description - the description of this option
presetValue - true: this option is on in default, false: off

addOption

public void addOption(OptionID optionID,
                      String shortOptionName,
                      String longOptionName,
                      String description,
                      OptionHandler<OptionID> handler)
Adds an option to this option group

Parameters:
optionID - the option ID
shortOptionName - the short option name. If you specified "h" as the argument, "-h" can be used as a command line option
longOptionName - the long option name. If you specified "help" as the argument, "--help" can be used as a command line option
description - the description of this option
handler - OptionHandler invoked when this option is set

addOption

public void addOption(OptionID optionID,
                      String shortOptionName,
                      String longOptionName,
                      String description,
                      boolean presetValue,
                      OptionHandler<OptionID> handler)
Adds an option to this option group

Parameters:
optionID - the option ID
shortOptionName - the short option name. If you specified "h" as the argument, "-h" can be used as a command line option
longOptionName - the long option name. If you specified "help" as the argument, "--help" can be used as a command line option
description - the description of this option
presetValue - true: this option is on in default, false: off
handler - OptionHandler invoked when this option is set

addOptionWithArgment

public void addOptionWithArgment(OptionID optionID,
                                 String shortOptionName,
                                 String longOptionName,
                                 String argumentName,
                                 String description)
Adds an option to this option group

Parameters:
optionID - the option ID
shortOptionName - the short option name. If you specified "h" as the argument, "-h" can be used as a command line option
longOptionName - the long option name. If you specified "help" as the argument, "--help" can be used as a command line option
argumentName - argument name of this option. This argument is used only for displaying the help message.
description - the description of this option
handler - OptionHandler invoked when this option is set

addOptionWithArgment

public void addOptionWithArgment(OptionID optionID,
                                 String shortOptionName,
                                 String longOptionName,
                                 String argumentName,
                                 String description,
                                 OptionHandler<OptionID> handler)
Adds an option to this option group

Parameters:
optionID - the option ID
shortOptionName - the short option name. If you specified "l" as the argument, "-l" can be used as a command line option
longOptionName - the long option name. If you specified "loglevel" as the argument, "--loglevel" can be used as a command line option
argumentName - argument name of this option. This argument is used only for displaying the help message.
description - the description of this option
handler - OptionHandler invoked when this option is set

addOptionWithArgment

public void addOptionWithArgment(OptionID optionID,
                                 String shortOptionName,
                                 String longOptionName,
                                 String argumentName,
                                 String description,
                                 String defaultValue)
Adds an option to this option group

Parameters:
optionID - the option ID
shortOptionName - the short option name. If you specified "h" as the argument, "-h" can be used as a command line option
longOptionName - the long option name. If you specified "help" as the argument, "--help" can be used as a command line option
argumentName - argument name of this option. This argument is used only for displaying the help message.
description - the description of this option
defaultValue - the default value of this option

addOptionGroup

public void addOptionGroup(OptionGroup<OptionID> optionGroup)

addOptionHandler

public void addOptionHandler(OptionID optionID,
                             OptionHandler<OptionID> handler)

collectOptionDescriptions

protected void collectOptionDescriptions(org.xerial.util.cui.OptionDescriptionContainer container)

findByLongOptionName

protected Option<OptionID> findByLongOptionName(String longOption)

findByShortOptionName

protected Option<OptionID> findByShortOptionName(String shortOption)

findOption

protected Option<OptionID> findOption(OptionID optionID)

collectOptionID

protected void collectOptionID(List<OptionID> optionIDList)

getOptionHandler

public OptionHandler<OptionID> getOptionHandler(OptionID optionID)
Finds the option handler of the specified optionID. This method recursively searches nested option groups

Parameters:
optionID - the option ID
Returns:
the option handler

isActive

public boolean isActive()

activate

public void activate()

getGroupName

public String getGroupName()

handle

public void handle(String[] args,
                   int argIndex)

setParent

protected void setParent(OptionGroup<OptionID> parentGroup)

getParent

protected OptionGroup<OptionID> getParent()

activateParentGroup

protected void activateParentGroup()


Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 2.1 Japan License.