From a5ea9c94b7f6cc3d1d24b0cac89f0956095fd6ac Mon Sep 17 00:00:00 2001 From: John Logan Date: Mon, 15 Sep 2025 16:40:46 -0700 Subject: [PATCH 1/5] Adds `aliases` to the dump-help output. - Closes #812. --- .../Usage/DumpHelpGenerator.swift | 1 + Sources/ArgumentParserToolInfo/ToolInfo.swift | 5 ++++ .../Snapshots/testADumpHelp().json | 6 +++++ .../Snapshots/testBDumpHelp().json | 6 +++++ .../Snapshots/testCDumpHelp().json | 6 +++++ .../Snapshots/testMathAddDumpHelp().json | 6 +++++ .../Snapshots/testMathDumpHelp().json | 24 +++++++++++++++++++ .../Snapshots/testMathMultiplyDumpHelp().json | 6 +++++ .../Snapshots/testMathStatsDumpHelp().json | 15 ++++++++++++ 9 files changed, 75 insertions(+) diff --git a/Sources/ArgumentParser/Usage/DumpHelpGenerator.swift b/Sources/ArgumentParser/Usage/DumpHelpGenerator.swift index 3ed2ac260..c1b9feb17 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 d4b8efaf9..c6b2e6fa5 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 self.abstract = abstract.nonEmpty self.discussion = discussion.nonEmpty @@ -89,6 +93,7 @@ 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.decode([String].self, forKey: .aliases) self.abstract = try container.decodeIfPresent( String.self, forKey: .abstract) self.discussion = try container.decodeIfPresent( diff --git a/Tests/ArgumentParserUnitTests/Snapshots/testADumpHelp().json b/Tests/ArgumentParserUnitTests/Snapshots/testADumpHelp().json index cb981545d..fcc628d7e 100644 --- a/Tests/ArgumentParserUnitTests/Snapshots/testADumpHelp().json +++ b/Tests/ArgumentParserUnitTests/Snapshots/testADumpHelp().json @@ -1,5 +1,8 @@ { "command" : { + "aliases" : [ + + ], "arguments" : [ { "allValues" : [ @@ -179,6 +182,9 @@ "subcommands" : [ { "abstract" : "Show subcommand help information.", + "aliases" : [ + + ], "arguments" : [ { "isOptional" : true, diff --git a/Tests/ArgumentParserUnitTests/Snapshots/testBDumpHelp().json b/Tests/ArgumentParserUnitTests/Snapshots/testBDumpHelp().json index 5b584df63..9f8857e05 100644 --- a/Tests/ArgumentParserUnitTests/Snapshots/testBDumpHelp().json +++ b/Tests/ArgumentParserUnitTests/Snapshots/testBDumpHelp().json @@ -1,5 +1,8 @@ { "command" : { + "aliases" : [ + + ], "arguments" : [ { "isOptional" : true, @@ -68,6 +71,9 @@ "subcommands" : [ { "abstract" : "Show subcommand help information.", + "aliases" : [ + + ], "arguments" : [ { "isOptional" : true, diff --git a/Tests/ArgumentParserUnitTests/Snapshots/testCDumpHelp().json b/Tests/ArgumentParserUnitTests/Snapshots/testCDumpHelp().json index 7cbcafeea..cb4f9e2a3 100644 --- a/Tests/ArgumentParserUnitTests/Snapshots/testCDumpHelp().json +++ b/Tests/ArgumentParserUnitTests/Snapshots/testCDumpHelp().json @@ -1,5 +1,8 @@ { "command" : { + "aliases" : [ + + ], "arguments" : [ { "abstract" : "A color to select.", @@ -202,6 +205,9 @@ "subcommands" : [ { "abstract" : "Show subcommand help information.", + "aliases" : [ + + ], "arguments" : [ { "isOptional" : true, diff --git a/Tests/ArgumentParserUnitTests/Snapshots/testMathAddDumpHelp().json b/Tests/ArgumentParserUnitTests/Snapshots/testMathAddDumpHelp().json index 51568de7c..2b75babde 100644 --- a/Tests/ArgumentParserUnitTests/Snapshots/testMathAddDumpHelp().json +++ b/Tests/ArgumentParserUnitTests/Snapshots/testMathAddDumpHelp().json @@ -1,6 +1,9 @@ { "command" : { "abstract" : "Print the sum of the values.", + "aliases" : [ + + ], "arguments" : [ { "abstract" : "Use hexadecimal notation for the result.", @@ -82,6 +85,9 @@ "subcommands" : [ { "abstract" : "Show subcommand help information.", + "aliases" : [ + + ], "arguments" : [ { "isOptional" : true, diff --git a/Tests/ArgumentParserUnitTests/Snapshots/testMathDumpHelp().json b/Tests/ArgumentParserUnitTests/Snapshots/testMathDumpHelp().json index badff7811..fa9174ee2 100644 --- a/Tests/ArgumentParserUnitTests/Snapshots/testMathDumpHelp().json +++ b/Tests/ArgumentParserUnitTests/Snapshots/testMathDumpHelp().json @@ -1,6 +1,9 @@ { "command" : { "abstract" : "A utility for performing maths.", + "aliases" : [ + + ], "arguments" : [ { "abstract" : "Show the version.", @@ -50,6 +53,9 @@ "subcommands" : [ { "abstract" : "Print the sum of the values.", + "aliases" : [ + + ], "arguments" : [ { "abstract" : "Use hexadecimal notation for the result.", @@ -134,6 +140,9 @@ }, { "abstract" : "Print the product of the values.", + "aliases" : [ + "mul" + ], "arguments" : [ { "abstract" : "Use hexadecimal notation for the result.", @@ -218,6 +227,9 @@ }, { "abstract" : "Calculate descriptive statistics.", + "aliases" : [ + + ], "arguments" : [ { "abstract" : "Show the version.", @@ -267,6 +279,9 @@ "subcommands" : [ { "abstract" : "Print the average of the values.", + "aliases" : [ + "avg" + ], "arguments" : [ { "abstract" : "The kind of average to provide.", @@ -363,6 +378,9 @@ }, { "abstract" : "Print the standard deviation of the values.", + "aliases" : [ + + ], "arguments" : [ { "abstract" : "A group of floating-point values to operate on.", @@ -425,6 +443,9 @@ }, { "abstract" : "Print the quantiles of the values (TBD).", + "aliases" : [ + + ], "arguments" : [ { "completionKind" : { @@ -726,6 +747,9 @@ }, { "abstract" : "Show subcommand help information.", + "aliases" : [ + + ], "arguments" : [ { "isOptional" : true, diff --git a/Tests/ArgumentParserUnitTests/Snapshots/testMathMultiplyDumpHelp().json b/Tests/ArgumentParserUnitTests/Snapshots/testMathMultiplyDumpHelp().json index 7494decf6..aa95b3a75 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.", @@ -82,6 +85,9 @@ "subcommands" : [ { "abstract" : "Show subcommand help information.", + "aliases" : [ + + ], "arguments" : [ { "isOptional" : true, diff --git a/Tests/ArgumentParserUnitTests/Snapshots/testMathStatsDumpHelp().json b/Tests/ArgumentParserUnitTests/Snapshots/testMathStatsDumpHelp().json index 0a1e95164..a0fe18d19 100644 --- a/Tests/ArgumentParserUnitTests/Snapshots/testMathStatsDumpHelp().json +++ b/Tests/ArgumentParserUnitTests/Snapshots/testMathStatsDumpHelp().json @@ -1,6 +1,9 @@ { "command" : { "abstract" : "Calculate descriptive statistics.", + "aliases" : [ + + ], "arguments" : [ { "abstract" : "Show the version.", @@ -50,6 +53,9 @@ "subcommands" : [ { "abstract" : "Print the average of the values.", + "aliases" : [ + "avg" + ], "arguments" : [ { "abstract" : "The kind of average to provide.", @@ -146,6 +152,9 @@ }, { "abstract" : "Print the standard deviation of the values.", + "aliases" : [ + + ], "arguments" : [ { "abstract" : "A group of floating-point values to operate on.", @@ -208,6 +217,9 @@ }, { "abstract" : "Print the quantiles of the values (TBD).", + "aliases" : [ + + ], "arguments" : [ { "completionKind" : { @@ -504,6 +516,9 @@ }, { "abstract" : "Show subcommand help information.", + "aliases" : [ + + ], "arguments" : [ { "isOptional" : true, From 701426e7ea749994009bed746c4fe9968e640973 Mon Sep 17 00:00:00 2001 From: John Logan Date: Mon, 15 Sep 2025 17:16:42 -0700 Subject: [PATCH 2/5] Adds aliases to ToolInfo test data. --- .../ArgumentParserToolInfoTests/Examples/example0.json | 5 ++++- .../ArgumentParserToolInfoTests/Examples/example1.json | 10 ++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Tests/ArgumentParserToolInfoTests/Examples/example0.json b/Tests/ArgumentParserToolInfoTests/Examples/example0.json index 901f01a9d..f63258942 100644 --- a/Tests/ArgumentParserToolInfoTests/Examples/example0.json +++ b/Tests/ArgumentParserToolInfoTests/Examples/example0.json @@ -1,6 +1,9 @@ { "serializationVersion": 0, "command": { - "commandName": "empty-example" + "commandName": "empty-example", + "aliases": [ + + ] } } diff --git a/Tests/ArgumentParserToolInfoTests/Examples/example1.json b/Tests/ArgumentParserToolInfoTests/Examples/example1.json index 43ae9b1e5..892372210 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", } - ] + ], } } From 166a5d31e17281a0ef6bdcb360562214bc0d4af6 Mon Sep 17 00:00:00 2001 From: John Logan Date: Tue, 16 Sep 2025 08:08:14 -0700 Subject: [PATCH 3/5] Makes ToolInfo aliases property optional. --- Sources/ArgumentParserToolInfo/ToolInfo.swift | 6 +++--- Tests/ArgumentParserToolInfoTests/Examples/example0.json | 5 +---- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/Sources/ArgumentParserToolInfo/ToolInfo.swift b/Sources/ArgumentParserToolInfo/ToolInfo.swift index c6b2e6fa5..469e09fa6 100644 --- a/Sources/ArgumentParserToolInfo/ToolInfo.swift +++ b/Sources/ArgumentParserToolInfo/ToolInfo.swift @@ -50,7 +50,7 @@ public struct CommandInfoV0: Codable, Hashable { /// Name used to invoke the command. public var commandName: String /// List of command aliases. - public var aliases: [String] + public var aliases: [String]? /// Short description of the command's functionality. public var abstract: String? /// Extended description of the command's functionality. @@ -68,7 +68,7 @@ public struct CommandInfoV0: Codable, Hashable { superCommands: [String], shouldDisplay: Bool, commandName: String, - aliases: [String], + aliases: [String]?, abstract: String, discussion: String, defaultSubcommand: String?, @@ -93,7 +93,7 @@ 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.decode([String].self, forKey: .aliases) + 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/example0.json b/Tests/ArgumentParserToolInfoTests/Examples/example0.json index f63258942..901f01a9d 100644 --- a/Tests/ArgumentParserToolInfoTests/Examples/example0.json +++ b/Tests/ArgumentParserToolInfoTests/Examples/example0.json @@ -1,9 +1,6 @@ { "serializationVersion": 0, "command": { - "commandName": "empty-example", - "aliases": [ - - ] + "commandName": "empty-example" } } From 92fd145e43c0b63b865ede428b620d6a828a88b1 Mon Sep 17 00:00:00 2001 From: John Logan Date: Tue, 16 Sep 2025 08:55:42 -0700 Subject: [PATCH 4/5] Fixes formatting. --- Sources/ArgumentParserToolInfo/ToolInfo.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sources/ArgumentParserToolInfo/ToolInfo.swift b/Sources/ArgumentParserToolInfo/ToolInfo.swift index 469e09fa6..35fe28a81 100644 --- a/Sources/ArgumentParserToolInfo/ToolInfo.swift +++ b/Sources/ArgumentParserToolInfo/ToolInfo.swift @@ -93,7 +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.aliases = try container.decodeIfPresent( + [String].self, forKey: .aliases) self.abstract = try container.decodeIfPresent( String.self, forKey: .abstract) self.discussion = try container.decodeIfPresent( From 385e641a85921c52bc0710ad44572d272ccdee38 Mon Sep 17 00:00:00 2001 From: Rauhul Varma Date: Mon, 12 Jan 2026 08:50:50 -0800 Subject: [PATCH 5/5] !fixup use non-empty aliases --- Sources/ArgumentParserToolInfo/ToolInfo.swift | 2 +- .../Snapshots/testADumpHelp().json | 6 ------ .../Snapshots/testBDumpHelp().json | 6 ------ .../Snapshots/testCDumpHelp().json | 6 ------ .../Snapshots/testMathAddDumpHelp().json | 6 ------ .../Snapshots/testMathDumpHelp().json | 18 ------------------ .../Snapshots/testMathMultiplyDumpHelp().json | 3 --- .../Snapshots/testMathStatsDumpHelp().json | 12 ------------ 8 files changed, 1 insertion(+), 58 deletions(-) diff --git a/Sources/ArgumentParserToolInfo/ToolInfo.swift b/Sources/ArgumentParserToolInfo/ToolInfo.swift index 35fe28a81..825799781 100644 --- a/Sources/ArgumentParserToolInfo/ToolInfo.swift +++ b/Sources/ArgumentParserToolInfo/ToolInfo.swift @@ -79,7 +79,7 @@ public struct CommandInfoV0: Codable, Hashable { self.shouldDisplay = shouldDisplay self.commandName = commandName - self.aliases = aliases + self.aliases = aliases?.nonEmpty self.abstract = abstract.nonEmpty self.discussion = discussion.nonEmpty diff --git a/Tests/ArgumentParserUnitTests/Snapshots/testADumpHelp().json b/Tests/ArgumentParserUnitTests/Snapshots/testADumpHelp().json index fcc628d7e..cb981545d 100644 --- a/Tests/ArgumentParserUnitTests/Snapshots/testADumpHelp().json +++ b/Tests/ArgumentParserUnitTests/Snapshots/testADumpHelp().json @@ -1,8 +1,5 @@ { "command" : { - "aliases" : [ - - ], "arguments" : [ { "allValues" : [ @@ -182,9 +179,6 @@ "subcommands" : [ { "abstract" : "Show subcommand help information.", - "aliases" : [ - - ], "arguments" : [ { "isOptional" : true, diff --git a/Tests/ArgumentParserUnitTests/Snapshots/testBDumpHelp().json b/Tests/ArgumentParserUnitTests/Snapshots/testBDumpHelp().json index 9f8857e05..5b584df63 100644 --- a/Tests/ArgumentParserUnitTests/Snapshots/testBDumpHelp().json +++ b/Tests/ArgumentParserUnitTests/Snapshots/testBDumpHelp().json @@ -1,8 +1,5 @@ { "command" : { - "aliases" : [ - - ], "arguments" : [ { "isOptional" : true, @@ -71,9 +68,6 @@ "subcommands" : [ { "abstract" : "Show subcommand help information.", - "aliases" : [ - - ], "arguments" : [ { "isOptional" : true, diff --git a/Tests/ArgumentParserUnitTests/Snapshots/testCDumpHelp().json b/Tests/ArgumentParserUnitTests/Snapshots/testCDumpHelp().json index cb4f9e2a3..7cbcafeea 100644 --- a/Tests/ArgumentParserUnitTests/Snapshots/testCDumpHelp().json +++ b/Tests/ArgumentParserUnitTests/Snapshots/testCDumpHelp().json @@ -1,8 +1,5 @@ { "command" : { - "aliases" : [ - - ], "arguments" : [ { "abstract" : "A color to select.", @@ -205,9 +202,6 @@ "subcommands" : [ { "abstract" : "Show subcommand help information.", - "aliases" : [ - - ], "arguments" : [ { "isOptional" : true, diff --git a/Tests/ArgumentParserUnitTests/Snapshots/testMathAddDumpHelp().json b/Tests/ArgumentParserUnitTests/Snapshots/testMathAddDumpHelp().json index 2b75babde..51568de7c 100644 --- a/Tests/ArgumentParserUnitTests/Snapshots/testMathAddDumpHelp().json +++ b/Tests/ArgumentParserUnitTests/Snapshots/testMathAddDumpHelp().json @@ -1,9 +1,6 @@ { "command" : { "abstract" : "Print the sum of the values.", - "aliases" : [ - - ], "arguments" : [ { "abstract" : "Use hexadecimal notation for the result.", @@ -85,9 +82,6 @@ "subcommands" : [ { "abstract" : "Show subcommand help information.", - "aliases" : [ - - ], "arguments" : [ { "isOptional" : true, diff --git a/Tests/ArgumentParserUnitTests/Snapshots/testMathDumpHelp().json b/Tests/ArgumentParserUnitTests/Snapshots/testMathDumpHelp().json index fa9174ee2..cca3abc42 100644 --- a/Tests/ArgumentParserUnitTests/Snapshots/testMathDumpHelp().json +++ b/Tests/ArgumentParserUnitTests/Snapshots/testMathDumpHelp().json @@ -1,9 +1,6 @@ { "command" : { "abstract" : "A utility for performing maths.", - "aliases" : [ - - ], "arguments" : [ { "abstract" : "Show the version.", @@ -53,9 +50,6 @@ "subcommands" : [ { "abstract" : "Print the sum of the values.", - "aliases" : [ - - ], "arguments" : [ { "abstract" : "Use hexadecimal notation for the result.", @@ -227,9 +221,6 @@ }, { "abstract" : "Calculate descriptive statistics.", - "aliases" : [ - - ], "arguments" : [ { "abstract" : "Show the version.", @@ -378,9 +369,6 @@ }, { "abstract" : "Print the standard deviation of the values.", - "aliases" : [ - - ], "arguments" : [ { "abstract" : "A group of floating-point values to operate on.", @@ -443,9 +431,6 @@ }, { "abstract" : "Print the quantiles of the values (TBD).", - "aliases" : [ - - ], "arguments" : [ { "completionKind" : { @@ -747,9 +732,6 @@ }, { "abstract" : "Show subcommand help information.", - "aliases" : [ - - ], "arguments" : [ { "isOptional" : true, diff --git a/Tests/ArgumentParserUnitTests/Snapshots/testMathMultiplyDumpHelp().json b/Tests/ArgumentParserUnitTests/Snapshots/testMathMultiplyDumpHelp().json index aa95b3a75..fbfb8a2ca 100644 --- a/Tests/ArgumentParserUnitTests/Snapshots/testMathMultiplyDumpHelp().json +++ b/Tests/ArgumentParserUnitTests/Snapshots/testMathMultiplyDumpHelp().json @@ -85,9 +85,6 @@ "subcommands" : [ { "abstract" : "Show subcommand help information.", - "aliases" : [ - - ], "arguments" : [ { "isOptional" : true, diff --git a/Tests/ArgumentParserUnitTests/Snapshots/testMathStatsDumpHelp().json b/Tests/ArgumentParserUnitTests/Snapshots/testMathStatsDumpHelp().json index a0fe18d19..432e78e5d 100644 --- a/Tests/ArgumentParserUnitTests/Snapshots/testMathStatsDumpHelp().json +++ b/Tests/ArgumentParserUnitTests/Snapshots/testMathStatsDumpHelp().json @@ -1,9 +1,6 @@ { "command" : { "abstract" : "Calculate descriptive statistics.", - "aliases" : [ - - ], "arguments" : [ { "abstract" : "Show the version.", @@ -152,9 +149,6 @@ }, { "abstract" : "Print the standard deviation of the values.", - "aliases" : [ - - ], "arguments" : [ { "abstract" : "A group of floating-point values to operate on.", @@ -217,9 +211,6 @@ }, { "abstract" : "Print the quantiles of the values (TBD).", - "aliases" : [ - - ], "arguments" : [ { "completionKind" : { @@ -516,9 +507,6 @@ }, { "abstract" : "Show subcommand help information.", - "aliases" : [ - - ], "arguments" : [ { "isOptional" : true,