Class ArgumentsOptionsParser<T>

java.lang.Object
org.eclipse.mosaic.lib.util.cli.ArgumentsOptionsParser<T>
Type Parameters:
T - class of the parameter object, which later holds the parsed parameter values

public class ArgumentsOptionsParser<T> extends Object
Automatically converts a list of arguments and options from the command line into a parameter object. The parameter object is expected to contain fields annotated with @CliOption or @CliArgument. CliArguments follows a strict order and are expected at the beginning of the input command call. After that, additional CliOptions follow, which have a short and/or long parameter name.
  • Constructor Details

    • ArgumentsOptionsParser

      public ArgumentsOptionsParser(Class<T> parameterClass)
      Constructs a new ArgumentsOptionsParser with a class of the object, which later holds the argument and option values. This must also declare all command line related properties, such as the name of the option and its description. For this, the fields in the given class need to be public and need to be annotated with a @CliArgument or @CliOption. Everything else is done by this parser.
  • Method Details

    • parseArguments

      public final T parseArguments(String[] args, T targetObject) throws org.apache.commons.cli.ParseException
      Parses a list of arguments (POSIX style) and writes the set values into the given parameter object. The parameter object should be of the same class as this parser is initialized with.
      Parameters:
      args - the input arguments from the command line.
      targetObject - the object which provides the required fields to fill in values parsed from the list of args.
      Throws:
      org.apache.commons.cli.ParseException
    • transformToArguments

      public final List<String> transformToArguments(T parameters)
      Transforms the object, which holds the parameter values into a list of arguments, which can be used to start MOSAIC processes with valid arguments.
      Throws:
      RuntimeException - if a field of the parameter class could not be transformed to an argument
    • printHelp

      public void printHelp(PrintWriter printWriter)
      Prints the help.
      Parameters:
      printWriter - writer to output help to
    • printHelp

      public void printHelp()
    • getOptions

      public final org.apache.commons.cli.Options getOptions()
      This method provides all options declared in the parameter object this parser has been initialized with.
    • usageHint

      public ArgumentsOptionsParser<T> usageHint(String usageHint, String header, String footer)
      This method is used to define a usage hint for the respective ArgumentsOptionsParser.
      Parameters:
      usageHint - the hint to be set
      header - header for the hint
      footer - footer for the hint
      Returns:
      the object to chain further methods