1 /* 2 * SPDX-FileCopyrightText: none 3 * SPDX-License-Identifier: CC0-1.0 4 */ 5 6 package gov.nist.secauto.metaschema.cli.processor; 7 8 import edu.umd.cs.findbugs.annotations.NonNull; 9 10 /** 11 * An enumeration of supported exit code values. 12 */ 13 public enum ExitCode { 14 /** 15 * The command executed without issue. 16 */ 17 OK(0), 18 /** 19 * The command executed properly, but the operation failed. 20 */ 21 FAIL(1), 22 /** 23 * An error occurred while reading or writing. 24 */ 25 IO_ERROR(2), 26 /** 27 * A command was requested by name that doesn't exist or required arguments are 28 * missing. 29 */ 30 INVALID_COMMAND(3), 31 /** 32 * The target argument was not found or invalid. 33 */ 34 INVALID_TARGET(4), 35 /** 36 * Handled errors that occur during command execution. 37 */ 38 PROCESSING_ERROR(5), 39 /** 40 * Unhandled errors that occur during command execution. 41 */ 42 RUNTIME_ERROR(6), 43 /** 44 * The provided argument information for a command fails to match argument use 45 * requirements. 46 */ 47 INVALID_ARGUMENTS(7); 48 49 private final int statusCode; 50 51 ExitCode(int statusCode) { 52 this.statusCode = statusCode; 53 } 54 55 /** 56 * Get the related status code for use with {@link System#exit(int)}. 57 * 58 * @return the statusCode 59 */ 60 public int getStatusCode() { 61 return statusCode; 62 } 63 64 /** 65 * Exit without a message. 66 * 67 * @return the exit status 68 */ 69 @NonNull 70 public ExitStatus exit() { 71 return new NonMessageExitStatus(this); 72 } 73 74 /** 75 * Exit with the associated message. 76 * 77 * @return the exit status 78 */ 79 @NonNull 80 public ExitStatus exitMessage() { 81 return new MessageExitStatus(this); 82 } 83 84 /** 85 * Exit with the associated message and message arguments. 86 * 87 * @param messageArguments 88 * any message parameters 89 * 90 * @return the exit status 91 */ 92 @NonNull 93 public ExitStatus exitMessage(@NonNull Object... messageArguments) { 94 return new MessageExitStatus(this, messageArguments); 95 } 96 }