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