import sys
from enum import IntEnum


class ExitStatus(IntEnum):
    """
    Exit Status definition based on http://tldp.org/LDP/abs/html/exitcodes.html
    """
    # Defined statuses
    SUCCESS = 0
    FAILURE = 1
    MISS_USAGE = 2
    UNABLE_TO_EXEC = 126
    COMMAND_NOT_FOUND = 127
    INVALID = 128
    KEYBOARD_INTERRUPT = 130
    OUT_OF_RANGE = 255

    # Undefined statuses
    EXIT_WITH_3 = 3
    EXIT_WITH_4 = 4
    EXIT_WITH_5 = 5
    EXIT_WITH_6 = 6
    EXIT_WITH_7 = 7
    EXIT_WITH_8 = 8
    EXIT_WITH_9 = 9
    EXIT_WITH_10 = 10
    EXIT_WITH_11 = 11
    EXIT_WITH_12 = 12
    EXIT_WITH_13 = 13
    EXIT_WITH_14 = 14
    EXIT_WITH_15 = 15
    EXIT_WITH_16 = 16
    EXIT_WITH_17 = 17
    EXIT_WITH_18 = 18
    EXIT_WITH_19 = 19
    EXIT_WITH_20 = 20
    EXIT_WITH_21 = 21
    EXIT_WITH_22 = 22
    EXIT_WITH_23 = 23
    EXIT_WITH_24 = 24
    EXIT_WITH_25 = 25
    EXIT_WITH_26 = 26
    EXIT_WITH_27 = 27
    EXIT_WITH_28 = 28
    EXIT_WITH_29 = 29
    EXIT_WITH_30 = 30
    EXIT_WITH_31 = 31
    EXIT_WITH_32 = 32
    EXIT_WITH_33 = 33
    EXIT_WITH_34 = 34
    EXIT_WITH_35 = 35
    EXIT_WITH_36 = 36
    EXIT_WITH_37 = 37
    EXIT_WITH_38 = 38
    EXIT_WITH_39 = 39
    EXIT_WITH_40 = 40
    EXIT_WITH_41 = 41
    EXIT_WITH_42 = 42
    EXIT_WITH_43 = 43
    EXIT_WITH_44 = 44
    EXIT_WITH_45 = 45
    EXIT_WITH_46 = 46
    EXIT_WITH_47 = 47
    EXIT_WITH_48 = 48
    EXIT_WITH_49 = 49
    EXIT_WITH_50 = 50
    EXIT_WITH_51 = 51
    EXIT_WITH_52 = 52
    EXIT_WITH_53 = 53
    EXIT_WITH_54 = 54
    EXIT_WITH_55 = 55
    EXIT_WITH_56 = 56
    EXIT_WITH_57 = 57
    EXIT_WITH_58 = 58
    EXIT_WITH_59 = 59
    EXIT_WITH_60 = 60
    EXIT_WITH_61 = 61
    EXIT_WITH_62 = 62
    EXIT_WITH_63 = 63
    EXIT_WITH_64 = 64
    EXIT_WITH_65 = 65
    EXIT_WITH_66 = 66
    EXIT_WITH_67 = 67
    EXIT_WITH_68 = 68
    EXIT_WITH_69 = 69
    EXIT_WITH_70 = 70
    EXIT_WITH_71 = 71
    EXIT_WITH_72 = 72
    EXIT_WITH_73 = 73
    EXIT_WITH_74 = 74
    EXIT_WITH_75 = 75
    EXIT_WITH_76 = 76
    EXIT_WITH_77 = 77
    EXIT_WITH_78 = 78
    EXIT_WITH_79 = 79
    EXIT_WITH_80 = 80
    EXIT_WITH_81 = 81
    EXIT_WITH_82 = 82
    EXIT_WITH_83 = 83
    EXIT_WITH_84 = 84
    EXIT_WITH_85 = 85
    EXIT_WITH_86 = 86
    EXIT_WITH_87 = 87
    EXIT_WITH_88 = 88
    EXIT_WITH_89 = 89
    EXIT_WITH_90 = 90
    EXIT_WITH_91 = 91
    EXIT_WITH_92 = 92
    EXIT_WITH_93 = 93
    EXIT_WITH_94 = 94
    EXIT_WITH_95 = 95
    EXIT_WITH_96 = 96
    EXIT_WITH_97 = 97
    EXIT_WITH_98 = 98
    EXIT_WITH_99 = 99
    EXIT_WITH_100 = 100
    EXIT_WITH_101 = 101
    EXIT_WITH_102 = 102
    EXIT_WITH_103 = 103
    EXIT_WITH_104 = 104
    EXIT_WITH_105 = 105
    EXIT_WITH_106 = 106
    EXIT_WITH_107 = 107
    EXIT_WITH_108 = 108
    EXIT_WITH_109 = 109
    EXIT_WITH_110 = 110
    EXIT_WITH_111 = 111
    EXIT_WITH_112 = 112
    EXIT_WITH_113 = 113
    EXIT_WITH_114 = 114
    EXIT_WITH_115 = 115
    EXIT_WITH_116 = 116
    EXIT_WITH_117 = 117
    EXIT_WITH_118 = 118
    EXIT_WITH_119 = 119
    EXIT_WITH_120 = 120
    EXIT_WITH_121 = 121
    EXIT_WITH_122 = 122
    EXIT_WITH_123 = 123
    EXIT_WITH_124 = 124
    EXIT_WITH_125 = 125

    # Fatal error signal `n`
    FATAL_SIGNAL_1 = 129
    FATAL_SIGNAL_3 = 131
    FATAL_SIGNAL_4 = 132
    FATAL_SIGNAL_5 = 133
    FATAL_SIGNAL_6 = 134
    FATAL_SIGNAL_7 = 135
    FATAL_SIGNAL_8 = 136
    FATAL_SIGNAL_9 = 137
    FATAL_SIGNAL_10 = 138
    FATAL_SIGNAL_11 = 139
    FATAL_SIGNAL_12 = 140
    FATAL_SIGNAL_13 = 141
    FATAL_SIGNAL_14 = 142
    FATAL_SIGNAL_15 = 143
    FATAL_SIGNAL_16 = 144
    FATAL_SIGNAL_17 = 145
    FATAL_SIGNAL_18 = 146
    FATAL_SIGNAL_19 = 147
    FATAL_SIGNAL_20 = 148
    FATAL_SIGNAL_21 = 149
    FATAL_SIGNAL_22 = 150
    FATAL_SIGNAL_23 = 151
    FATAL_SIGNAL_24 = 152
    FATAL_SIGNAL_25 = 153
    FATAL_SIGNAL_26 = 154
    FATAL_SIGNAL_27 = 155
    FATAL_SIGNAL_28 = 156
    FATAL_SIGNAL_29 = 157
    FATAL_SIGNAL_30 = 158
    FATAL_SIGNAL_31 = 159
    FATAL_SIGNAL_32 = 160
    FATAL_SIGNAL_33 = 161
    FATAL_SIGNAL_34 = 162
    FATAL_SIGNAL_35 = 163
    FATAL_SIGNAL_36 = 164
    FATAL_SIGNAL_37 = 165
    FATAL_SIGNAL_38 = 166
    FATAL_SIGNAL_39 = 167
    FATAL_SIGNAL_40 = 168
    FATAL_SIGNAL_41 = 169
    FATAL_SIGNAL_42 = 170
    FATAL_SIGNAL_43 = 171
    FATAL_SIGNAL_44 = 172
    FATAL_SIGNAL_45 = 173
    FATAL_SIGNAL_46 = 174
    FATAL_SIGNAL_47 = 175
    FATAL_SIGNAL_48 = 176
    FATAL_SIGNAL_49 = 177
    FATAL_SIGNAL_50 = 178
    FATAL_SIGNAL_51 = 179
    FATAL_SIGNAL_52 = 180
    FATAL_SIGNAL_53 = 181
    FATAL_SIGNAL_54 = 182
    FATAL_SIGNAL_55 = 183
    FATAL_SIGNAL_56 = 184
    FATAL_SIGNAL_57 = 185
    FATAL_SIGNAL_58 = 186
    FATAL_SIGNAL_59 = 187
    FATAL_SIGNAL_60 = 188
    FATAL_SIGNAL_61 = 189
    FATAL_SIGNAL_62 = 190
    FATAL_SIGNAL_63 = 191
    FATAL_SIGNAL_64 = 192
    FATAL_SIGNAL_65 = 193
    FATAL_SIGNAL_66 = 194
    FATAL_SIGNAL_67 = 195
    FATAL_SIGNAL_68 = 196
    FATAL_SIGNAL_69 = 197
    FATAL_SIGNAL_70 = 198
    FATAL_SIGNAL_71 = 199
    FATAL_SIGNAL_72 = 200
    FATAL_SIGNAL_73 = 201
    FATAL_SIGNAL_74 = 202
    FATAL_SIGNAL_75 = 203
    FATAL_SIGNAL_76 = 204
    FATAL_SIGNAL_77 = 205
    FATAL_SIGNAL_78 = 206
    FATAL_SIGNAL_79 = 207
    FATAL_SIGNAL_80 = 208
    FATAL_SIGNAL_81 = 209
    FATAL_SIGNAL_82 = 210
    FATAL_SIGNAL_83 = 211
    FATAL_SIGNAL_84 = 212
    FATAL_SIGNAL_85 = 213
    FATAL_SIGNAL_86 = 214
    FATAL_SIGNAL_87 = 215
    FATAL_SIGNAL_88 = 216
    FATAL_SIGNAL_89 = 217
    FATAL_SIGNAL_90 = 218
    FATAL_SIGNAL_91 = 219
    FATAL_SIGNAL_92 = 220
    FATAL_SIGNAL_93 = 221
    FATAL_SIGNAL_94 = 222
    FATAL_SIGNAL_95 = 223
    FATAL_SIGNAL_96 = 224
    FATAL_SIGNAL_97 = 225
    FATAL_SIGNAL_98 = 226
    FATAL_SIGNAL_99 = 227
    FATAL_SIGNAL_100 = 228
    FATAL_SIGNAL_101 = 229
    FATAL_SIGNAL_102 = 230
    FATAL_SIGNAL_103 = 231
    FATAL_SIGNAL_104 = 232
    FATAL_SIGNAL_105 = 233
    FATAL_SIGNAL_106 = 234
    FATAL_SIGNAL_107 = 235
    FATAL_SIGNAL_108 = 236
    FATAL_SIGNAL_109 = 237
    FATAL_SIGNAL_110 = 238
    FATAL_SIGNAL_111 = 239
    FATAL_SIGNAL_112 = 240
    FATAL_SIGNAL_113 = 241
    FATAL_SIGNAL_114 = 242
    FATAL_SIGNAL_115 = 243
    FATAL_SIGNAL_116 = 244
    FATAL_SIGNAL_117 = 245
    FATAL_SIGNAL_118 = 246
    FATAL_SIGNAL_119 = 247
    FATAL_SIGNAL_120 = 248
    FATAL_SIGNAL_121 = 249
    FATAL_SIGNAL_122 = 250
    FATAL_SIGNAL_123 = 251
    FATAL_SIGNAL_124 = 252
    FATAL_SIGNAL_125 = 253
    FATAL_SIGNAL_126 = 254

    # Python 3.5 do not support `_missing_` API
    if sys.version_info >= (3, 6):
        @classmethod
        def _missing_(cls, value):
            if isinstance(value, int):
                return cls.OUT_OF_RANGE
            return cls.INVALID
