diff --git a/Sources/ArgumentParser/Usage/DumpHelpGenerator.swift b/Sources/ArgumentParser/Usage/DumpHelpGenerator.swift index 3ed2ac26..c1b9feb1 100644 --- a/Sources/ArgumentParser/Usage/DumpHelpGenerator.swift +++ b/Sources/ArgumentParser/Usage/DumpHelpGenerator.swift @@ -87,6 +87,7 @@ extension CommandInfoV0 { superCommands: superCommands, shouldDisplay: command.configuration.shouldDisplay, commandName: command._commandName, + aliases: command.configuration.aliases, abstract: command.configuration.abstract, discussion: command.configuration.discussion, defaultSubcommand: defaultSubcommand, diff --git a/Sources/ArgumentParserToolInfo/ToolInfo.swift b/Sources/ArgumentParserToolInfo/ToolInfo.swift index d4b8efaf..82579978 100644 --- a/Sources/ArgumentParserToolInfo/ToolInfo.swift +++ b/Sources/ArgumentParserToolInfo/ToolInfo.swift @@ -49,6 +49,8 @@ public struct CommandInfoV0: Codable, Hashable { /// Name used to invoke the command. public var commandName: String + /// List of command aliases. + public var aliases: [String]? /// Short description of the command's functionality. public var abstract: String? /// Extended description of the command's functionality. @@ -66,6 +68,7 @@ public struct CommandInfoV0: Codable, Hashable { superCommands: [String], shouldDisplay: Bool, commandName: String, + aliases: [String]?, abstract: String, discussion: String, defaultSubcommand: String?, @@ -76,6 +79,7 @@ public struct CommandInfoV0: Codable, Hashable { self.shouldDisplay = shouldDisplay self.commandName = commandName + self.aliases = aliases?.nonEmpty self.abstract = abstract.nonEmpty self.discussion = discussion.nonEmpty @@ -89,6 +93,8 @@ public struct CommandInfoV0: Codable, Hashable { self.superCommands = try container.decodeIfPresent( [String].self, forKey: .superCommands) self.commandName = try container.decode(String.self, forKey: .commandName) + self.aliases = try container.decodeIfPresent( + [String].self, forKey: .aliases) self.abstract = try container.decodeIfPresent( String.self, forKey: .abstract) self.discussion = try container.decodeIfPresent( diff --git a/Tests/ArgumentParserToolInfoTests/Examples/example1.json b/Tests/ArgumentParserToolInfoTests/Examples/example1.json index 43ae9b1e..89237221 100644 --- a/Tests/ArgumentParserToolInfoTests/Examples/example1.json +++ b/Tests/ArgumentParserToolInfoTests/Examples/example1.json @@ -6,12 +6,18 @@ "parent1" ], "commandName": "full-example", + "aliases": [ + + ], "abstract": "this command does everything", "discussion": "like actually everything", "defaultSubcommand": "do-thing", "subcommands": [ { - "commandName": "sub" + "commandName": "sub", + "aliases": [ + + ] } ], "arguments": [ @@ -63,6 +69,6 @@ "isRepeating": false, "parsingStrategy" : "default", } - ] + ], } } diff --git a/Tests/ArgumentParserUnitTests/Snapshots/testMathDumpHelp().json b/Tests/ArgumentParserUnitTests/Snapshots/testMathDumpHelp().json index badff781..cca3abc4 100644 --- a/Tests/ArgumentParserUnitTests/Snapshots/testMathDumpHelp().json +++ b/Tests/ArgumentParserUnitTests/Snapshots/testMathDumpHelp().json @@ -134,6 +134,9 @@ }, { "abstract" : "Print the product of the values.", + "aliases" : [ + "mul" + ], "arguments" : [ { "abstract" : "Use hexadecimal notation for the result.", @@ -267,6 +270,9 @@ "subcommands" : [ { "abstract" : "Print the average of the values.", + "aliases" : [ + "avg" + ], "arguments" : [ { "abstract" : "The kind of average to provide.", diff --git a/Tests/ArgumentParserUnitTests/Snapshots/testMathMultiplyDumpHelp().json b/Tests/ArgumentParserUnitTests/Snapshots/testMathMultiplyDumpHelp().json index 7494decf..fbfb8a2c 100644 --- a/Tests/ArgumentParserUnitTests/Snapshots/testMathMultiplyDumpHelp().json +++ b/Tests/ArgumentParserUnitTests/Snapshots/testMathMultiplyDumpHelp().json @@ -1,6 +1,9 @@ { "command" : { "abstract" : "Print the product of the values.", + "aliases" : [ + "mul" + ], "arguments" : [ { "abstract" : "Use hexadecimal notation for the result.", diff --git a/Tests/ArgumentParserUnitTests/Snapshots/testMathStatsDumpHelp().json b/Tests/ArgumentParserUnitTests/Snapshots/testMathStatsDumpHelp().json index 0a1e9516..432e78e5 100644 --- a/Tests/ArgumentParserUnitTests/Snapshots/testMathStatsDumpHelp().json +++ b/Tests/ArgumentParserUnitTests/Snapshots/testMathStatsDumpHelp().json @@ -50,6 +50,9 @@ "subcommands" : [ { "abstract" : "Print the average of the values.", + "aliases" : [ + "avg" + ], "arguments" : [ { "abstract" : "The kind of average to provide.",