From cc5ad952b5c585a6b1aa2715d7ffac567d2dee33 Mon Sep 17 00:00:00 2001 From: John Logan Date: Mon, 15 Sep 2025 16:40:46 -0700 Subject: [PATCH 1/4] 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 01e3b89ee..2b885d7d3 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 725c51f63..d719e02ca 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 a580e11588a102981654f32a43bd8272455c9501 Mon Sep 17 00:00:00 2001 From: John Logan Date: Mon, 15 Sep 2025 17:16:42 -0700 Subject: [PATCH 2/4] 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 f283f8f44cd5f6891bf9c803f79adb08146fdcbe Mon Sep 17 00:00:00 2001 From: John Logan Date: Tue, 16 Sep 2025 08:08:14 -0700 Subject: [PATCH 3/4] 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 857fe55611d5ab585d908211b766d3a494378c24 Mon Sep 17 00:00:00 2001 From: John Logan Date: Tue, 16 Sep 2025 08:55:42 -0700 Subject: [PATCH 4/4] 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(