Skip to content
Merged
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
17 changes: 11 additions & 6 deletions Sources/ArgumentParser/Usage/HelpGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal struct HelpGenerator {
}

struct Section {
struct Element {
struct Element: Hashable {
var label: String
var abstract: String = ""
var discussion: String = ""
Expand Down Expand Up @@ -125,7 +125,9 @@ internal struct HelpGenerator {
static func generateSections(commandStack: [ParsableCommand.Type]) -> [Section] {
var positionalElements: [Section.Element] = []
var optionElements: [Section.Element] = []

/// Used to keep track of elements already seen from parent commands.
var alreadySeenElements = Set<Section.Element>()

for commandType in commandStack {
let args = Array(ArgumentSet(commandType))

Expand Down Expand Up @@ -158,10 +160,13 @@ internal struct HelpGenerator {
}

let element = Section.Element(label: synopsis, abstract: description, discussion: arg.help.help?.discussion ?? "")
if case .positional = arg.kind {
positionalElements.append(element)
} else {
optionElements.append(element)
if !alreadySeenElements.contains(element) {
alreadySeenElements.insert(element)
if case .positional = arg.kind {
positionalElements.append(element)
} else {
optionElements.append(element)
}
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions Tests/EndToEndTests/SubcommandEndToEndTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ extension SubcommandEndToEndTests {
USAGE: foo a --name <name> --bar <bar>

OPTIONS:
--name <name>
--name <name>
--bar <bar>
-h, --help Show help information.
Expand All @@ -96,7 +95,6 @@ extension SubcommandEndToEndTests {
USAGE: foo b --name <name> --baz <baz>

OPTIONS:
--name <name>
--name <name>
--baz <baz>
-h, --help Show help information.
Expand Down