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

Issue:
Default value not displayed in help for Flags built from CaseIterable enums
When using flags built from a `(String & CaseIterable)` enum, such as this:
```
enum OutputBehaviour: String, CaseIterable { case stats, count, list }

struct Options: ParsableCommand {
  @Flag(name: .short, default: .list, exclusivity: .chooseFirst, help: "Help!")
  var behaviour: OutputBehaviour
}

let options = Options.parseOrExit()
```

The corresponding line in the help message does not display the default value.

The Flag initializer passes the default value along to the ArgumentDefinition constructor, but when the array of ArgumentDefinition is read back in HelpGenerator, the `help.defaultValue` properties for these is `nil`.

Pull request description:
This fixes https://github.com/apple/swift-argument-parser/issues/56

Patch:
diff --git a/Sources/ArgumentParser/Parsable Properties/Flag.swift b/Sources/ArgumentParser/Parsable Properties/Flag.swift
index 67f97f131..d7795c28a 100644
--- a/Sources/ArgumentParser/Parsable Properties/Flag.swift
+++ b/Sources/ArgumentParser/Parsable Properties/Flag.swift
@@ -240,10 +240,11 @@ extension Flag where Value: CaseIterable, Value: RawRepresentable, Value.RawValu
       // This gets flipped to `true` the first time one of these flags is
       // encountered.
       var hasUpdated = false
-      
+      let defaultValue = initial.map(String.init(describing:))
+
       let args = Value.allCases.map { value -> ArgumentDefinition in
         let caseKey = InputKey(rawValue: value.rawValue)
-        let help = ArgumentDefinition.Help(options: initial != nil ? .isOptional : [], help: help, key: key)
+        let help = ArgumentDefinition.Help(options: initial != nil ? .isOptional : [], help: help, defaultValue: defaultValue, key: key)
         return ArgumentDefinition.flag(name: name, key: key, caseKey: caseKey, help: help, parsingStrategy: .nextAsValue, initialValue: initial, update: .nullary({ (origin, name, values) in
           // TODO: We should catch duplicate flags that hit a single part of
           // an exclusive argument set in the value parsing, not here.


Test patch:
diff --git a/Tests/UnitTests/HelpGenerationTests.swift b/Tests/UnitTests/HelpGenerationTests.swift
index 90397c378..a7ce9fd35 100644
--- a/Tests/UnitTests/HelpGenerationTests.swift
+++ b/Tests/UnitTests/HelpGenerationTests.swift
@@ -100,6 +100,7 @@ extension HelpGenerationTests {
             """)
   }
 
+  enum OptionFlags: String, CaseIterable { case optional, required }
   struct D: ParsableCommand {
 
     @Option(default: "John", help: "Your name.")
@@ -110,16 +111,20 @@ extension HelpGenerationTests {
 
     @Option(default: false, help: "Whether logging is enabled.")
     var logging: Bool
+
+    @Flag(default: .optional, help: "Vegan diet.")
+    var nda: OptionFlags
   }
 
   func testHelpWithDefaultValues() {
     AssertHelp(for: D.self, equals: """
-            USAGE: d [--name <name>] [--age <age>] [--logging <logging>]
+            USAGE: d [--name <name>] [--age <age>] [--logging <logging>] [--optional] [--required]
 
             OPTIONS:
               --name <name>           Your name. (default: John)
               --age <age>             Your age. (default: 20)
               --logging <logging>     Whether logging is enabled. (default: false)
+              --optional/--required   Vegan diet. (default: optional)
               -h, --help              Show help information.
 
             """)
@@ -154,7 +159,7 @@ extension HelpGenerationTests {
                USAGE: f [-s] [-c] [-l]
 
                OPTIONS:
-                 -s/-c/-l                Change the program output
+                 -s/-c/-l                Change the program output (default: list)
                  -h, --help              Show help information.
 
                """)