Interface CLIBeanSpec

All Superinterfaces:
ConfigBeanSpec

@ClassVersion(sourceVersion="$Id: CLIBeanSpec.java 1164 2026-03-20 17:38:18Z tquadrat $") @API(status=STABLE, since="0.0.1") public interface CLIBeanSpec extends ConfigBeanSpec

When a configuration bean should be initialised from the command line, the respective specification interface needs to extend this interface.

If none of the getters in the extended interface is annotated with either @Option or @Argument, the compilation failed because the generated class does not implement the methods from this interface (dumpParamFileTemplate(OutputStream), parseCommandLine(String[]), printUsage(OutputStream, CharSequence) and retrieveParseErrorMessage()). The error message will be something like "<Generated Class> is not abstract".

Author:
Thomas Thrien (thomas.thrien@tquadrat.org)
Version:
$Id: CLIBeanSpec.java 1164 2026-03-20 17:38:18Z tquadrat $
Since:
0.0.1
UML Diagram
UML Diagram for "org.tquadrat.foundation.config.CLIBeanSpec"

UML Diagram for "org.tquadrat.foundation.config.CLIBeanSpec"

UML Diagram for "org.tquadrat.foundation.config.CLIBeanSpec"
  • Field Details

  • Method Details

    • dumpParamFileTemplate

      void dumpParamFileTemplate(OutputStream outputStream) throws IOException
      Dumps a parameter file template to the given OutputStream.
      Parameters:
      outputStream - The target output stream.
      Throws:
      IOException - Something went wrong when writing to the output stream.
      See Also:
    • parseCommandLine

      boolean parseCommandLine(String[] args)

      Parses the command line.

      As a result from parsing the given command line arguments, the accordingly annotated properties will be initialised with the values from the command line.

      Arguments starting with @ (like @param.lst) are treated as a file that contains further arguments.

      Assuming the file param.lst has the following contents:

      -opt0
      value0
      -opt1
      value1
      --
      arg0
      arg1

      and args looks like this:

      -opt value @param.lst arg
      ,

      the resulting command line arguments set would be:

      -opt value -opt0 value0 -opt1 value1 -- arg0 arg1 arg

      In case the file could not be opened for whatever reason, the parameter will not be replaced – meaning the resulting command line would have the value @param.lst as one value.

      Parameters:
      args - The command line arguments; usually the same as the arguments to the method main().
      Returns:
      true if the command line could be parsed without issues, false otherwise.
    • printUsage

      void printUsage(OutputStream outputStream, CharSequence command) throws IOException
      Prints a usage message to the given OutputStream.
      Parameters:
      outputStream - The output stream.
      command - The command used to start the program.
      Throws:
      IOException - A problem occurred on writing to the output stream.
    • retrieveParseErrorMessage

      Retrieves the message for the error caused by the last call to parseCommandLine(String[]), given that this return false.
      Returns:
      An instance of Optional that holds the error message.