001/*
002 * SPDX-FileCopyrightText: none
003 * SPDX-License-Identifier: CC0-1.0
004 */
005
006package gov.nist.secauto.metaschema.cli.processor;
007
008import edu.umd.cs.findbugs.annotations.NonNull;
009
010public enum ExitCode {
011  /**
012   * The command executed without issue.
013   */
014  OK(0),
015  /**
016   * The command executed properly, but the operation failed.
017   */
018  FAIL(1),
019  /**
020   * An error occurred while reading or writing.
021   */
022  IO_ERROR(2),
023  /**
024   * A command was requested by name that doesn't exist or required arguments are
025   * missing.
026   */
027  INVALID_COMMAND(3),
028  /**
029   * The target argument was not found or invalid.
030   */
031  INVALID_TARGET(4),
032  /**
033   * Handled errors that occur during command execution.
034   */
035  PROCESSING_ERROR(5),
036  /**
037   * Unhandled errors that occur during command execution.
038   */
039  RUNTIME_ERROR(6),
040  /**
041   * The provided argument information for a command fails to match argument use
042   * requirements.
043   */
044  INVALID_ARGUMENTS(7);
045
046  private final int statusCode;
047
048  ExitCode(int statusCode) {
049    this.statusCode = statusCode;
050  }
051
052  /**
053   * Get the related status code for use with {@link System#exit(int)}.
054   *
055   * @return the statusCode
056   */
057  public int getStatusCode() {
058    return statusCode;
059  }
060
061  /**
062   * Exit without a message.
063   *
064   * @return the exit status
065   */
066  @NonNull
067  public ExitStatus exit() {
068    return new NonMessageExitStatus(this);
069  }
070
071  /**
072   * Exit with the associated message.
073   *
074   * @return the exit status
075   */
076  @NonNull
077  public ExitStatus exitMessage() {
078    return new MessageExitStatus(this);
079  }
080
081  /**
082   * Exit with the associated message and message arguments.
083   *
084   * @param messageArguments
085   *          any message parameters
086   *
087   * @return the exit status
088   */
089  @NonNull
090  public ExitStatus exitMessage(@NonNull Object... messageArguments) {
091    return new MessageExitStatus(this, messageArguments);
092  }
093}