Class Parser

java.lang.Object
org.rwtodd.args.Parser

public class Parser extends Object
Parses command-line arguments against given Params.
  • Constructor Details

    • Parser

      public Parser(Param... ps)
      Construct a command-line parser from a set of Param objects.
      Parameters:
      ps - the parameters to use for parsing.
  • Method Details

    • parse

      public List<String> parse(String[] args, int skip) throws ArgParserException
      parses the given args, and returns any elements that don't appear to be params in an array.
      Parameters:
      args - the command-line arguments
      skip - how many entries in args to skip before processing
      Returns:
      any non-param strings from the input
      Throws:
      ArgParserException - when a problem is encountered
    • parse

      public List<String> parse(String[] args) throws ArgParserException
      parses the given args, and returns any elements that don't appear to be params in an array. It skips no arguments, since in java, there is no first argument with a program name. To skip a different amount (for instance, if your command-line had subcommands to parse prior to command-line args), call the overload of this method that has 2 arguments.
      Parameters:
      args - the command-line arguments
      Returns:
      any non-param strings from the input
      Throws:
      ArgParserException - when a problem is encountered
    • printHelpText

      public void printHelpText(PrintStream ps)
      Print help text for each parameter given to us by the user. The parametrs are printed in the same order they were provided.
      Parameters:
      ps - the print stream to use for output.