Class ParamParser

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

public 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.

  • Constructor Details

    • ParamParser

      public ParamParser(String spec)
  • Method Details

    • getUsage

      public String getUsage(String commandName)
      Build a usage summary string.
      Parameters:
      commandName - command name
      Returns:
      usage string
    • 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 Parser<?> getParser(String typeName)
      Convert parameter spec type name into a Parser.

      The implementation in ParamParser supports all of the pre-defined types of EncodingRegistry (identified by their encoding ID's or aliases), plus word to parse a String containing one or more non-whitespace characters. Subclasses should override as required to add additional supported types.

      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