1 /*
2 * Portions of this software was developed by employees of the National Institute
3 * of Standards and Technology (NIST), an agency of the Federal Government and is
4 * being made available as a public service. Pursuant to title 17 United States
5 * Code Section 105, works of NIST employees are not subject to copyright
6 * protection in the United States. This software may be subject to foreign
7 * copyright. Permission in the United States and in foreign countries, to the
8 * extent that NIST may hold copyright, to use, copy, modify, create derivative
9 * works, and distribute this software and its documentation without fee is hereby
10 * granted on a non-exclusive basis, provided that this notice and disclaimer
11 * of warranty appears in all copies.
12 *
13 * THE SOFTWARE IS PROVIDED 'AS IS' WITHOUT ANY WARRANTY OF ANY KIND, EITHER
14 * EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, ANY WARRANTY
15 * THAT THE SOFTWARE WILL CONFORM TO SPECIFICATIONS, ANY IMPLIED WARRANTIES OF
16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND FREEDOM FROM
17 * INFRINGEMENT, AND ANY WARRANTY THAT THE DOCUMENTATION WILL CONFORM TO THE
18 * SOFTWARE, OR ANY WARRANTY THAT THE SOFTWARE WILL BE ERROR FREE. IN NO EVENT
19 * SHALL NIST BE LIABLE FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO, DIRECT,
20 * INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES, ARISING OUT OF, RESULTING FROM,
21 * OR IN ANY WAY CONNECTED WITH THIS SOFTWARE, WHETHER OR NOT BASED UPON WARRANTY,
22 * CONTRACT, TORT, OR OTHERWISE, WHETHER OR NOT INJURY WAS SUSTAINED BY PERSONS OR
23 * PROPERTY OR OTHERWISE, AND WHETHER OR NOT LOSS WAS SUSTAINED FROM, OR AROSE OUT
24 * OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER.
25 */
26
27 package gov.nist.secauto.metaschema.cli.processor;
28
29 import edu.umd.cs.findbugs.annotations.NonNull;
30
31 public enum ExitCode {
32 /**
33 * The command executed without issue.
34 */
35 OK(0),
36 /**
37 * The command executed properly, but the operation failed.
38 */
39 FAIL(1),
40 /**
41 * An error occurred while reading or writing.
42 */
43 IO_ERROR(2),
44 /**
45 * A command was requested by name that doesn't exist or required arguments are
46 * missing.
47 */
48 INVALID_COMMAND(3),
49 /**
50 * The target argument was not found or invalid.
51 */
52 INVALID_TARGET(4),
53 /**
54 * Handled errors that occur during command execution.
55 */
56 PROCESSING_ERROR(5),
57 /**
58 * Unhandled errors that occur during command execution.
59 */
60 RUNTIME_ERROR(6),
61 /**
62 * The provided argument information for a command fails to match argument use
63 * requirements.
64 */
65 INVALID_ARGUMENTS(7);
66
67 private final int statusCode;
68
69 ExitCode(int statusCode) {
70 this.statusCode = statusCode;
71 }
72
73 /**
74 * Get the related status code for use with {@link System#exit(int)}.
75 *
76 * @return the statusCode
77 */
78 public int getStatusCode() {
79 return statusCode;
80 }
81
82 /**
83 * Exit without a message.
84 *
85 * @return the exit status
86 */
87 @NonNull
88 public ExitStatus exit() {
89 return new NonMessageExitStatus(this);
90 }
91
92 /**
93 * Exit with the associated message.
94 *
95 * @return the exit status
96 */
97 @NonNull
98 public ExitStatus exitMessage() {
99 return new MessageExitStatus(this);
100 }
101
102 /**
103 * Exit with the associated message and message arguments.
104 *
105 * @param messageArguments
106 * any message parameters
107 *
108 * @return the exit status
109 */
110 @NonNull
111 public ExitStatus exitMessage(@NonNull Object... messageArguments) {
112 return new MessageExitStatus(this, messageArguments);
113 }
114 }