Class ParamParser

java.lang.Object
io.permazen.cli.ParamParser

public abstract class ParamParser extends Object
Parses command line parameters, including optional flags, based on a specification string.

The specification string contains whitespace-separated parameter specifications; see ParamParser.Param for syntax. Subclasses must provide the parsers for the parameter type specification names via getParser(String).

  • Constructor Details

    • ParamParser

      public ParamParser(String spec)
  • Method Details

    • getUsage

      public String getUsage()
      Build a usage summary string.
      Returns:
      usage string, not including the command name
    • getOptionFlags

      public Set<ParamParser.Param> getOptionFlags()
      Get option flags.
      Returns:
      optional parameters
    • getParameters

      public List<ParamParser.Param> getParameters()
      Get regular parameters, in expected order.
      Returns:
      mandatory parameters
    • getParser

      protected abstract Parser<?> getParser(String typeName)
      Convert parameter spec type name into a Parser.
      Parameters:
      typeName - name of type
      Returns:
      parser for parameters of the specified type
      Throws:
      IllegalArgumentException - if typeName is unknown
    • parse

      public Map<String,Object> parse(Session session, List<String> params)
      Parse command line parameters.
      Parameters:
      session - associated session
      params - command parameters
      Throws:
      ParseException - if parse fails