Skip to content

Commit ab0f98f

Browse files
committed
Use the customization point for Optional default values in help
1 parent e371989 commit ab0f98f

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

Sources/ArgumentParser/Parsable Types/ExpressibleByArgument.swift

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ public protocol ExpressibleByArgument {
2121
var defaultValueDescription: String { get }
2222
}
2323

24+
extension ExpressibleByArgument {
25+
public var defaultValueDescription: String {
26+
"\(self)"
27+
}
28+
}
29+
2430
extension String: ExpressibleByArgument {
2531
public init?(argument: String) {
2632
self = argument
@@ -35,6 +41,13 @@ extension Optional: ExpressibleByArgument where Wrapped: ExpressibleByArgument {
3541
return nil
3642
}
3743
}
44+
45+
public var defaultValueDescription: String {
46+
guard let value = self else {
47+
return "none"
48+
}
49+
return "\(value)"
50+
}
3851
}
3952

4053
extension RawRepresentable where Self: ExpressibleByArgument, RawValue: ExpressibleByArgument {
@@ -70,17 +83,3 @@ extension Float: ExpressibleByArgument {}
7083
extension Double: ExpressibleByArgument {}
7184

7285
extension Bool: ExpressibleByArgument {}
73-
74-
extension ExpressibleByArgument {
75-
76-
public var defaultValueDescription: String {
77-
78-
let mirror = Mirror(reflecting: self)
79-
80-
if mirror.displayStyle == .optional, let value = mirror.children.first?.value {
81-
return "\(value)"
82-
}
83-
84-
return "\(self)"
85-
}
86-
}

0 commit comments

Comments
 (0)