9
9
//
10
10
//===----------------------------------------------------------------------===//
11
11
12
- @_implementationOnly import Foundation
12
+ @_implementationOnly import protocol Foundation. LocalizedError
13
+ @_implementationOnly import class Foundation. NSError
13
14
14
15
enum MessageInfo {
15
16
case help( text: String )
16
17
case validation( message: String , usage: String , help: String )
17
- case other( message: String , exitCode: Int32 )
18
+ case other( message: String , exitCode: ExitCode )
18
19
19
20
init ( error: Error , type: ParsableArguments . Type ) {
20
21
var commandStack : [ ParsableCommand . Type ]
@@ -105,15 +106,15 @@ enum MessageInfo {
105
106
case . message( let message) :
106
107
self = . help( text: message)
107
108
}
108
- case let error as ExitCode :
109
- self = . other( message: " " , exitCode: error . rawValue )
109
+ case let exitCode as ExitCode :
110
+ self = . other( message: " " , exitCode: exitCode )
110
111
case let error as LocalizedError where error. errorDescription != nil :
111
- self = . other( message: error. errorDescription!, exitCode: EXIT_FAILURE )
112
+ self = . other( message: error. errorDescription!, exitCode: . failure )
112
113
default :
113
114
if Swift . type ( of: error) is NSError . Type {
114
- self = . other( message: error. localizedDescription, exitCode: EXIT_FAILURE )
115
+ self = . other( message: error. localizedDescription, exitCode: . failure )
115
116
} else {
116
- self = . other( message: String ( describing: error) , exitCode: EXIT_FAILURE )
117
+ self = . other( message: String ( describing: error) , exitCode: . failure )
117
118
}
118
119
}
119
120
} else if let parserError = parserError {
@@ -126,7 +127,7 @@ enum MessageInfo {
126
127
let helpAbstract = argumentSet. helpDescription ( error: parserError) ?? " "
127
128
self = . validation( message: message, usage: usage, help: helpAbstract)
128
129
} else {
129
- self = . other( message: String ( describing: error) , exitCode: EXIT_FAILURE )
130
+ self = . other( message: String ( describing: error) , exitCode: . failure )
130
131
}
131
132
}
132
133
@@ -165,7 +166,7 @@ enum MessageInfo {
165
166
switch self {
166
167
case . help: return ExitCode . success
167
168
case . validation: return ExitCode . validationFailure
168
- case . other( _, let code ) : return ExitCode ( code )
169
+ case . other( _, let exitCode ) : return exitCode
169
170
}
170
171
}
171
172
}
0 commit comments