From e392dea804a48bd74990ab23f79b7fbdba0c3c14 Mon Sep 17 00:00:00 2001 From: Artem Novichkov Date: Wed, 10 Jun 2020 09:34:26 +0600 Subject: [PATCH 1/3] Update label for default subcommand --- Sources/ArgumentParser/Usage/HelpGenerator.swift | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Sources/ArgumentParser/Usage/HelpGenerator.swift b/Sources/ArgumentParser/Usage/HelpGenerator.swift index 26ac4301c..44d9b03fc 100644 --- a/Sources/ArgumentParser/Usage/HelpGenerator.swift +++ b/Sources/ArgumentParser/Usage/HelpGenerator.swift @@ -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) } From 337d81f40490e74e5b9ac0a91e25ab8059460df6 Mon Sep 17 00:00:00 2001 From: Artem Novichkov Date: Wed, 10 Jun 2020 09:46:13 +0600 Subject: [PATCH 2/3] Add test for default subcommand --- .../HelpGenerationTests.swift | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Tests/ArgumentParserUnitTests/HelpGenerationTests.swift b/Tests/ArgumentParserUnitTests/HelpGenerationTests.swift index 338ad8baa..48539f452 100644 --- a/Tests/ArgumentParserUnitTests/HelpGenerationTests.swift +++ b/Tests/ArgumentParserUnitTests/HelpGenerationTests.swift @@ -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 + + OPTIONS: + -h, --help Show help information. + + SUBCOMMANDS: + m (default) + + See 'n help ' for detailed help. + """) + } } From 1cb6cf6e44cd1643a1bfc8fbd434bb26e071632e Mon Sep 17 00:00:00 2001 From: Artem Novichkov Date: Thu, 11 Jun 2020 08:36:05 +0600 Subject: [PATCH 3/3] Fix test fixtures with default subcommand help message --- Tests/ArgumentParserExampleTests/MathExampleTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/ArgumentParserExampleTests/MathExampleTests.swift b/Tests/ArgumentParserExampleTests/MathExampleTests.swift index cd0761462..7515f9b0a 100644 --- a/Tests/ArgumentParserExampleTests/MathExampleTests.swift +++ b/Tests/ArgumentParserExampleTests/MathExampleTests.swift @@ -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.