Skip to content

Commit 9e86019

Browse files
authored
treat empty strings and nil strings the same way in help output (#47)
1 parent b9eb417 commit 9e86019

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

Sources/ArgumentParser/Usage/HelpGenerator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ internal struct HelpGenerator {
150150
i += 1
151151

152152
} else {
153-
let defaultValue = arg.help.defaultValue.flatMap { "(default: \($0))" } ?? ""
153+
let defaultValue = arg.help.defaultValue.flatMap { $0.isEmpty ? nil : "(default: \($0))" } ?? ""
154154
synopsis = arg.synopsisForHelp ?? ""
155155
description = [arg.help.help?.abstract, defaultValue]
156156
.compactMap { $0 }

Tests/UnitTests/HelpGenerationTests.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,21 @@ extension HelpGenerationTests {
8080
var two: String
8181
@Option(help: "The third option")
8282
var three: String
83+
@Option(default: nil, help: "A fourth option")
84+
var four: String?
85+
@Option(default: "", help: "A fifth option")
86+
var five: String
8387
}
8488

8589
func testHelpWithDefaultValueButNoDiscussion() {
8690
AssertHelp(for: Issue27.self, equals: """
87-
USAGE: issue27 [--two <two>] --three <three>
91+
USAGE: issue27 [--two <two>] --three <three> [--four <four>] [--five <five>]
8892
8993
OPTIONS:
9094
--two <two> (default: 42)
9195
--three <three> The third option
96+
--four <four> A fourth option
97+
--five <five> A fifth option
9298
-h, --help Show help information.
9399
94100
""")

0 commit comments

Comments
 (0)