diff --git a/Sources/ArgumentParser/Usage/DumpHelpGenerator.swift b/Sources/ArgumentParser/Usage/DumpHelpGenerator.swift index a3ace186..e1b56243 100644 --- a/Sources/ArgumentParser/Usage/DumpHelpGenerator.swift +++ b/Sources/ArgumentParser/Usage/DumpHelpGenerator.swift @@ -135,6 +135,7 @@ fileprivate extension CommandInfoV0 { self = CommandInfoV0( superCommands: superCommands, commandName: command._commandName, + shouldDisplay: command.configuration.shouldDisplay, abstract: command.configuration.abstract, discussion2: .init(command.configuration.discussion), defaultSubcommand: defaultSubcommand, diff --git a/Sources/ArgumentParserToolInfo/ToolInfo.swift b/Sources/ArgumentParserToolInfo/ToolInfo.swift index 12c7a8fc..bd6c37cb 100644 --- a/Sources/ArgumentParserToolInfo/ToolInfo.swift +++ b/Sources/ArgumentParserToolInfo/ToolInfo.swift @@ -111,7 +111,7 @@ public struct CommandInfoV0: Codable, Hashable { /// Custom CodingKeys names. enum CodingKeys: String, CodingKey { case discussion2 = "discussion" - case superCommands, commandName, abstract, defaultSubcommand, subcommands, arguments + case superCommands, commandName, abstract, defaultSubcommand, subcommands, arguments, shouldDisplay } /// Super commands and tools. @@ -143,6 +143,9 @@ public struct CommandInfoV0: Codable, Hashable { /// for a custom `CaseIterable` type), or can describe /// a static block of text that extends the description of the argument. public var discussion2: Discussion? + + /// Command should appear in help displays. + public var shouldDisplay: Bool = true /// Optional name of the subcommand invoked when the command is invoked with /// no arguments. @@ -155,6 +158,7 @@ public struct CommandInfoV0: Codable, Hashable { public init( superCommands: [String], commandName: String, + shouldDisplay: Bool, abstract: String, discussion2: Discussion?, defaultSubcommand: String?, @@ -164,6 +168,7 @@ public struct CommandInfoV0: Codable, Hashable { self.superCommands = superCommands.nonEmpty self.commandName = commandName + self.shouldDisplay = shouldDisplay self.abstract = abstract.nonEmpty self.discussion2 = discussion2 self.defaultSubcommand = defaultSubcommand?.nonEmpty @@ -186,6 +191,7 @@ public struct CommandInfoV0: Codable, Hashable { self.init( superCommands: superCommands, commandName: commandName, + shouldDisplay: true, abstract: abstract, discussion2: discussion, defaultSubcommand: defaultSubcommand, @@ -244,7 +250,7 @@ public struct ArgumentInfoV0: Codable, Hashable { public var shouldDisplay: Bool /// Custom name of argument's section. public var sectionTitle: String? - + /// Argument can be omitted. public var isOptional: Bool /// Argument can be specified multiple times. @@ -311,7 +317,7 @@ public struct ArgumentInfoV0: Codable, Hashable { self.shouldDisplay = shouldDisplay self.sectionTitle = sectionTitle - + self.isOptional = isOptional self.isRepeating = isRepeating diff --git a/Tests/ArgumentParserUnitTests/DumpHelpGenerationTests.swift b/Tests/ArgumentParserUnitTests/DumpHelpGenerationTests.swift index eb2918a4..12481b20 100644 --- a/Tests/ArgumentParserUnitTests/DumpHelpGenerationTests.swift +++ b/Tests/ArgumentParserUnitTests/DumpHelpGenerationTests.swift @@ -90,6 +90,8 @@ extension DumpHelpGenerationTests { @Option(help: .init(discussion: "A discussion.")) var discussion: String + + static var configuration = CommandConfiguration(shouldDisplay: false) } public func testDumpA() throws { @@ -277,7 +279,8 @@ extension DumpHelpGenerationTests { "valueName" : "help" } ], - "commandName" : "a" + "commandName" : "a", + "shouldDisplay" : true }, "serializationVersion" : 0 } @@ -346,7 +349,8 @@ extension DumpHelpGenerationTests { "valueName" : "help" } ], - "commandName" : "b" + "commandName" : "b", + "shouldDisplay" : true }, "serializationVersion" : 0 } @@ -594,7 +598,8 @@ extension DumpHelpGenerationTests { "valueName" : "help" } ], - "commandName" : "c" + "commandName" : "c", + "shouldDisplay" : false }, "serializationVersion" : 0 } @@ -647,6 +652,7 @@ extension DumpHelpGenerationTests { } ], "commandName" : "math", + "shouldDisplay" : true, "subcommands" : [ { "abstract" : "Print the sum of the values.", @@ -723,6 +729,7 @@ extension DumpHelpGenerationTests { } ], "commandName" : "add", + "shouldDisplay" : true, "superCommands" : [ "math" ] @@ -802,6 +809,7 @@ extension DumpHelpGenerationTests { } ], "commandName" : "multiply", + "shouldDisplay" : true, "superCommands" : [ "math" ] @@ -851,6 +859,7 @@ extension DumpHelpGenerationTests { } ], "commandName" : "stats", + "shouldDisplay" : true, "subcommands" : [ { "abstract" : "Print the average of the values.", @@ -929,6 +938,7 @@ extension DumpHelpGenerationTests { } ], "commandName" : "average", + "shouldDisplay" : true, "superCommands" : [ "math", "stats" @@ -987,6 +997,7 @@ extension DumpHelpGenerationTests { } ], "commandName" : "stdev", + "shouldDisplay" : true, "superCommands" : [ "math", "stats" @@ -1195,6 +1206,7 @@ extension DumpHelpGenerationTests { } ], "commandName" : "quantiles", + "shouldDisplay" : true, "superCommands" : [ "math", "stats" @@ -1289,6 +1301,7 @@ extension DumpHelpGenerationTests { } ], "commandName" : "add", + "shouldDisplay" : true, "superCommands" : [ "math" ] @@ -1375,6 +1388,7 @@ extension DumpHelpGenerationTests { } ], "commandName" : "multiply", + "shouldDisplay" : true, "superCommands" : [ "math" ] @@ -1431,6 +1445,7 @@ extension DumpHelpGenerationTests { } ], "commandName" : "stats", + "shouldDisplay" : true, "subcommands" : [ { "abstract" : "Print the average of the values.", @@ -1509,6 +1524,7 @@ extension DumpHelpGenerationTests { } ], "commandName" : "average", + "shouldDisplay" : true, "superCommands" : [ "math", "stats" @@ -1567,6 +1583,7 @@ extension DumpHelpGenerationTests { } ], "commandName" : "stdev", + "shouldDisplay" : true, "superCommands" : [ "math", "stats" @@ -1775,6 +1792,7 @@ extension DumpHelpGenerationTests { } ], "commandName" : "quantiles", + "shouldDisplay" : true, "superCommands" : [ "math", "stats"