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
9 changes: 7 additions & 2 deletions Sources/ArgumentParser/Usage/HelpGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,16 @@ internal struct HelpGenerator {
optionElements.append(.init(label: helpLabels, abstract: "Show help information."))
}

let configuration = commandStack.last!.configuration
let subcommandElements: [Section.Element] =
commandStack.last!.configuration.subcommands.compactMap { command in
configuration.subcommands.compactMap { command in
guard command.configuration.shouldDisplay else { return nil }
var label = command._commandName
if command == configuration.defaultSubcommand {
label += " (default)"
}
return Section.Element(
label: command._commandName,
label: label,
abstract: command.configuration.abstract)
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/ArgumentParserExampleTests/MathExampleTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ final class MathExampleTests: XCTestCase {
-h, --help Show help information.

SUBCOMMANDS:
add Print the sum of the values.
add (default) Print the sum of the values.
multiply Print the product of the values.
stats Calculate descriptive statistics.

Expand Down
20 changes: 20 additions & 0 deletions Tests/ArgumentParserUnitTests/HelpGenerationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -377,4 +377,24 @@ extension HelpGenerationTests {

""")
}

struct M: ParsableCommand {
}
struct N: ParsableCommand {
static var configuration = CommandConfiguration(subcommands: [M.self], defaultSubcommand: M.self)
}

func testHelpWithDefaultCommand() {
AssertHelp(for: N.self, equals: """
USAGE: n <subcommand>

OPTIONS:
-h, --help Show help information.

SUBCOMMANDS:
m (default)

See 'n help <subcommand>' for detailed help.
""")
}
}