Class CLIProcessor

java.lang.Object
gov.nist.secauto.metaschema.cli.processor.CLIProcessor

public class CLIProcessor extends Object
Processes command line arguments and dispatches called commands.

This implementation make significant use of the command pattern to support a delegation chain of commands based on implementations of ICommand.

  • Field Details

    • HELP_OPTION

      @NonNull public static final org.apache.commons.cli.Option HELP_OPTION
      This option indicates if the help should be shown.
    • NO_COLOR_OPTION

      @NonNull public static final org.apache.commons.cli.Option NO_COLOR_OPTION
      This option indicates if colorized output should be disabled.
    • QUIET_OPTION

      @NonNull public static final org.apache.commons.cli.Option QUIET_OPTION
      This option indicates if non-errors should be suppressed.
    • SHOW_STACK_TRACE_OPTION

      @NonNull public static final org.apache.commons.cli.Option SHOW_STACK_TRACE_OPTION
      This option indicates if a strack trace should be shown for an error ExitStatus.
    • VERSION_OPTION

      @NonNull public static final org.apache.commons.cli.Option VERSION_OPTION
      This option indicates if the version information should be shown.
    • COMMAND_VERSION

      public static final String COMMAND_VERSION
      Used to identify the version info for the command.
      See Also:
  • Constructor Details

    • CLIProcessor

      public CLIProcessor(@NonNull String args)
      The main entry point for CLI processing.

      This uses the build-in version information.

      Parameters:
      args - the command line arguments
    • CLIProcessor

      public CLIProcessor(@NonNull String exec, @NonNull Map<String,IVersionInfo> versionInfos)
      The main entry point for CLI processing.

      This uses the provided version information.

      Parameters:
      exec - the command name
      versionInfos - the version info to display when the version option is provided
  • Method Details

    • main

      public static void main(String... args)
      The main entry point for command execution.
      Parameters:
      args - the command line arguments to process
    • getExec

      @NonNull public String getExec()
      Gets the command used to execute for use in help text.
      Returns:
      the command name
    • getVersionInfos

      @NonNull public Map<String,IVersionInfo> getVersionInfos()
      Retrieve the version information for this application.
      Returns:
      the versionInfo
    • addCommandHandler

      public void addCommandHandler(@NonNull ICommand handler)
      Register a new command handler.
      Parameters:
      handler - the command handler to register
    • process

      @NonNull public ExitStatus process(String... args)
      Process a set of CLIProcessor arguments.

      process().getExitCode().getStatusCode()

      Parameters:
      args - the arguments to process
      Returns:
      the exit status
    • getTopLevelCommands

      @NonNull protected final List<ICommand> getTopLevelCommands()
      Get the root-level commands.
      Returns:
      the list of commands
    • getTopLevelCommandsByName

      @NonNull protected final Map<String,ICommand> getTopLevelCommandsByName()
      Get the root-level commands, mapped from name to command.
      Returns:
      the map of command names to command
    • handleQuiet

      public static void handleQuiet()
      Configure the logger to only report errors.
    • showVersion

      protected void showVersion()
      Output version information.