Class CommandLineParser

java.lang.Object
com.yahoo.system.CommandLineParser

public class CommandLineParser extends Object
Simple command line parser, handling multiple arguments and multiple unary and binary switches starting with -. Terms used: progname -binaryswitch foo -unaryswitch argument1 argument2
Author:
vegardh
  • Constructor Details

    • CommandLineParser

      public CommandLineParser(String[] cmds)
    • CommandLineParser

      public CommandLineParser(String progname, String[] cmds)
  • Method Details

    • parse

      public void parse()
      Parses the command line
      Throws:
      IllegalArgumentException - if a parse error occured
    • addLegalUnarySwitch

      public void addLegalUnarySwitch(String s, String explanation)
      Add a legal unary switch such as "-d"
    • addLegalUnarySwitch

      public void addLegalUnarySwitch(String s)
    • addRequiredUnarySwitch

      public void addRequiredUnarySwitch(String s, String explanation)
      Adds a required switch, such as -p
    • addLegalBinarySwitch

      public void addLegalBinarySwitch(String s, String explanation)
      Add a legal binary switch such as "-f /foo/bar"
    • addLegalBinarySwitch

      public void addLegalBinarySwitch(String s)
      Adds a legal binary switch without explanation
    • addRequiredBinarySwitch

      public void addRequiredBinarySwitch(String s, String explanation)
      Adds a required binary switch
    • getUnarySwitches

      public List<String> getUnarySwitches()
      The unary switches that were given on the command line
    • getBinarySwitches

      public Map<String,String> getBinarySwitches()
      The binary switches that were given on the command line
    • getArguments

      public List<String> getArguments()
      All non-switch strings that were given on the command line
    • setArgumentExplanation

      public void setArgumentExplanation(String argumentExplanation)
      Sets the argument explanation used in printing method, i.e. "names,..."
    • setExtendedHelpText

      public void setExtendedHelpText(String text)
    • getHelpText

      public String getHelpText()
    • setMinArguments

      public void setMinArguments(int minArguments)
      Sets minimum number of required arguments
    • setMaxArguments

      public void setMaxArguments(int maxArguments)
      Sets the maximum number of allowed arguments
    • helpSwitchUsed

      public boolean helpSwitchUsed()