Repository: apple/swift-argument-parser (swift)

Issue:
Default Option value in help text includes `Optional(…)`
the following option

```swift
@Option(default: true)
var doStuff: Bool?
```

would result in the following default value description:

```
(default: Optional(true))
```

This is counterintuitive and requires user to workaround it.

Pull request:
Fixes #26

Patch:
diff --git a/Sources/ArgumentParser/Parsable Types/ExpressibleByArgument.swift b/Sources/ArgumentParser/Parsable Types/ExpressibleByArgument.swift
index dd989a333..f516ca102 100644
--- a/Sources/ArgumentParser/Parsable Types/ExpressibleByArgument.swift
+++ b/Sources/ArgumentParser/Parsable Types/ExpressibleByArgument.swift
@@ -66,3 +66,16 @@ extension Double: ExpressibleByArgument {}
 
 extension Bool: ExpressibleByArgument {}
 
+extension ExpressibleByArgument {
+
+  var defaultValueDescription: String {
+
+    let mirror = Mirror(reflecting: self)
+
+    if mirror.displayStyle == .optional, let value = mirror.children.first?.value {
+        return "\(value)"
+    }
+
+    return "\(self)"
+  }
+}
diff --git a/Sources/ArgumentParser/Parsing/ArgumentSet.swift b/Sources/ArgumentParser/Parsing/ArgumentSet.swift
index b60300da1..b8d8149db 100644
--- a/Sources/ArgumentParser/Parsing/ArgumentSet.swift
+++ b/Sources/ArgumentParser/Parsing/ArgumentSet.swift
@@ -235,7 +235,7 @@ extension ArgumentSet {
   init<A: ExpressibleByArgument>(key: InputKey, kind: ArgumentDefinition.Kind, parsingStrategy: ArgumentDefinition.ParsingStrategy = .nextAsValue, parseType type: A.Type, name: NameSpecification, default initial: A?, help: ArgumentHelp?) {
     var arg = ArgumentDefinition(key: key, kind: kind, parsingStrategy: parsingStrategy, parser: A.init(argument:), default: initial)
     arg.help.help = help
-    arg.help.defaultValue = initial.map { "\($0)" }
+    arg.help.defaultValue = initial.map { "\($0.defaultValueDescription)" }
     self.init(arg)
   }
 }


Test patch:
diff --git a/Tests/ArgumentParserUnitTests/HelpGenerationTests.swift b/Tests/ArgumentParserUnitTests/HelpGenerationTests.swift
index 4a5fdb060..205eb8d0d 100644
--- a/Tests/ArgumentParserUnitTests/HelpGenerationTests.swift
+++ b/Tests/ArgumentParserUnitTests/HelpGenerationTests.swift
@@ -108,6 +108,9 @@ extension HelpGenerationTests {
     @Option(default: "John", help: "Your name.")
     var name: String
 
+    @Option(default: "Winston", help: "Your middle name.")
+    var middleName: String?
+
     @Option(default: 20, help: "Your age.")
     var age: Int
 
@@ -120,13 +123,15 @@ extension HelpGenerationTests {
 
   func testHelpWithDefaultValues() {
     AssertHelp(for: D.self, equals: """
-            USAGE: d [<occupation>] [--name <name>] [--age <age>] [--logging <logging>] [--optional] [--required]
+            USAGE: d [<occupation>] [--name <name>] [--middle-name <middle-name>] [--age <age>] [--logging <logging>] [--optional] [--required]
 
             ARGUMENTS:
               <occupation>            Your occupation. (default: --)
 
             OPTIONS:
               --name <name>           Your name. (default: John)
+              --middle-name <middle-name>
+                                      Your middle name. (default: Winston)
               --age <age>             Your age. (default: 20)
               --logging <logging>     Whether logging is enabled. (default: false)
               --optional/--required   Vegan diet. (default: optional)