Skip to content

Commit 52e6700

Browse files
authored
ArgumentKind improvements (#44)
* use Bool(_:) instead of manual parsing * improve ShellCompletion documentation * make Bool init(argument:) consistent with Int init(argument:) * plural
1 parent 7b1b819 commit 52e6700

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

Sources/TSCUtility/ArgumentParser.swift

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -128,19 +128,27 @@ public enum Shell: String, StringEnumArgument {
128128

129129
/// Various shell completions modes supplied by ArgumentKind.
130130
public enum ShellCompletion {
131-
/// Offers no completions at all; e.g. for a string identifier.
131+
/// Offers no completions at all.
132+
///
133+
/// e.g. for a string identifier.
132134
case none
133135

134-
/// No specific completions, will offer tool's completions.
136+
/// No specific completions.
137+
///
138+
/// The tool will provide its own completions.
135139
case unspecified
136140

137141
/// Offers filename completions.
138142
case filename
139143

140-
/// Custom function for generating completions. Must be provided in the script's scope.
144+
/// Custom function for generating completions.
145+
///
146+
/// Must be provided in the script's scope.
141147
case function(String)
142148

143-
/// Offers completions from predefined list. A description can be provided which is shown in some shells, like zsh.
149+
/// Offers completions from a predefined list.
150+
///
151+
/// A description can be provided which is shown in some shells, like zsh.
144152
case values([(value: String, description: String)])
145153
}
146154

@@ -180,14 +188,11 @@ extension Int: ArgumentKind {
180188

181189
extension Bool: ArgumentKind {
182190
public init(argument: String) throws {
183-
switch argument {
184-
case "true":
185-
self = true
186-
case "false":
187-
self = false
188-
default:
191+
guard let bool = Bool(argument) else {
189192
throw ArgumentConversionError.unknown(value: argument)
190193
}
194+
195+
self = bool
191196
}
192197

193198
public static var completion: ShellCompletion = .unspecified

0 commit comments

Comments
 (0)