Skip to content

Commit 4143a35

Browse files
authored
Remove extraneous newline for empty abstract (#161)
In the event a configuration has an empty abstract and non-empty discussion, an extra line was generated. This patch removes that line. ISSUE: SAP-156 #156
1 parent f18ce1a commit 4143a35

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

Sources/ArgumentParser/Usage/HelpGenerator.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,10 @@ internal struct HelpGenerator {
117117

118118
self.abstract = currentCommand.configuration.abstract
119119
if !currentCommand.configuration.discussion.isEmpty {
120-
self.abstract += "\n\n\(currentCommand.configuration.discussion)"
120+
if !self.abstract.isEmpty {
121+
self.abstract += "\n"
122+
}
123+
self.abstract += "\n\(currentCommand.configuration.discussion)"
121124
}
122125

123126
self.usage = Usage(components: [usageString])

Tests/ArgumentParserUnitTests/HelpGenerationTests.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,4 +298,23 @@ extension HelpGenerationTests {
298298
""")
299299

300300
}
301+
302+
struct J: ParsableCommand {
303+
static var configuration = CommandConfiguration(discussion: "test")
304+
}
305+
306+
func testOverviewButNoAbstractSpacing() {
307+
let renderedHelp = HelpGenerator(J.self).rendered()
308+
AssertEqualStringsIgnoringTrailingWhitespace(renderedHelp, """
309+
OVERVIEW:
310+
test
311+
312+
USAGE: j
313+
314+
OPTIONS:
315+
-h, --help Show help information.
316+
317+
""")
318+
}
319+
301320
}

0 commit comments

Comments
 (0)