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