Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion Sources/ArgumentParser/Usage/HelpGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,19 @@ extension BidirectionalCollection where Element == ParsableCommand.Type {
})
else { return ArgumentSet() }
self.versionArgumentDefinition().map { arguments.append($0) }
self.helpArgumentDefinition().map { arguments.append($0) }

let shouldAppendBuiltinHelp = !arguments
.flatMap(\.names)
.contains { name in
if case .short(let char, _) = name {
return char == "h"
}
return false
}

if shouldAppendBuiltinHelp {
self.helpArgumentDefinition().map { arguments.append($0) }
}

// To add when 'dump-help' is public API:
// arguments.append(self.dumpHelpArgumentDefinition())
Expand Down
25 changes: 25 additions & 0 deletions Tests/ArgumentParserUnitTests/HelpGenerationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1493,3 +1493,28 @@ extension HelpGenerationTests {
#endif
}
}

extension HelpGenerationTests {
struct Issue778: ParsableCommand {
@Argument(help: "The phrase to repeat.")
var phrase: String

@Option(name: .shortAndLong, help: "The name of the talking horse.")
var horse: String
}

func testCommandWithShortOptionNameHDoesNotIncludeBuiltInHelp() {
AssertHelp(
.default, for: Issue778.self, columns: nil,
equals: """
USAGE: issue778 <phrase> --horse <horse>

ARGUMENTS:
<phrase> The phrase to repeat.

OPTIONS:
-h, --horse <horse> The name of the talking horse.

""")
}
}