Skip to content

Commit bbf95b7

Browse files
authored
Adds aliases to the dump-help output. (#813)
1 parent 5d8546f commit bbf95b7

6 files changed

Lines changed: 27 additions & 2 deletions

File tree

Sources/ArgumentParser/Usage/DumpHelpGenerator.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ extension CommandInfoV0 {
8787
superCommands: superCommands,
8888
shouldDisplay: command.configuration.shouldDisplay,
8989
commandName: command._commandName,
90+
aliases: command.configuration.aliases,
9091
abstract: command.configuration.abstract,
9192
discussion: command.configuration.discussion,
9293
defaultSubcommand: defaultSubcommand,

Sources/ArgumentParserToolInfo/ToolInfo.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ public struct CommandInfoV0: Codable, Hashable {
4949

5050
/// Name used to invoke the command.
5151
public var commandName: String
52+
/// List of command aliases.
53+
public var aliases: [String]?
5254
/// Short description of the command's functionality.
5355
public var abstract: String?
5456
/// Extended description of the command's functionality.
@@ -66,6 +68,7 @@ public struct CommandInfoV0: Codable, Hashable {
6668
superCommands: [String],
6769
shouldDisplay: Bool,
6870
commandName: String,
71+
aliases: [String]?,
6972
abstract: String,
7073
discussion: String,
7174
defaultSubcommand: String?,
@@ -76,6 +79,7 @@ public struct CommandInfoV0: Codable, Hashable {
7679
self.shouldDisplay = shouldDisplay
7780

7881
self.commandName = commandName
82+
self.aliases = aliases?.nonEmpty
7983
self.abstract = abstract.nonEmpty
8084
self.discussion = discussion.nonEmpty
8185

@@ -89,6 +93,8 @@ public struct CommandInfoV0: Codable, Hashable {
8993
self.superCommands = try container.decodeIfPresent(
9094
[String].self, forKey: .superCommands)
9195
self.commandName = try container.decode(String.self, forKey: .commandName)
96+
self.aliases = try container.decodeIfPresent(
97+
[String].self, forKey: .aliases)
9298
self.abstract = try container.decodeIfPresent(
9399
String.self, forKey: .abstract)
94100
self.discussion = try container.decodeIfPresent(

Tests/ArgumentParserToolInfoTests/Examples/example1.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,18 @@
66
"parent1"
77
],
88
"commandName": "full-example",
9+
"aliases": [
10+
11+
],
912
"abstract": "this command does everything",
1013
"discussion": "like actually everything",
1114
"defaultSubcommand": "do-thing",
1215
"subcommands": [
1316
{
14-
"commandName": "sub"
17+
"commandName": "sub",
18+
"aliases": [
19+
20+
]
1521
}
1622
],
1723
"arguments": [
@@ -63,6 +69,6 @@
6369
"isRepeating": false,
6470
"parsingStrategy" : "default",
6571
}
66-
]
72+
],
6773
}
6874
}

Tests/ArgumentParserUnitTests/Snapshots/testMathDumpHelp().json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@
134134
},
135135
{
136136
"abstract" : "Print the product of the values.",
137+
"aliases" : [
138+
"mul"
139+
],
137140
"arguments" : [
138141
{
139142
"abstract" : "Use hexadecimal notation for the result.",
@@ -267,6 +270,9 @@
267270
"subcommands" : [
268271
{
269272
"abstract" : "Print the average of the values.",
273+
"aliases" : [
274+
"avg"
275+
],
270276
"arguments" : [
271277
{
272278
"abstract" : "The kind of average to provide.",

Tests/ArgumentParserUnitTests/Snapshots/testMathMultiplyDumpHelp().json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{
22
"command" : {
33
"abstract" : "Print the product of the values.",
4+
"aliases" : [
5+
"mul"
6+
],
47
"arguments" : [
58
{
69
"abstract" : "Use hexadecimal notation for the result.",

Tests/ArgumentParserUnitTests/Snapshots/testMathStatsDumpHelp().json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@
5050
"subcommands" : [
5151
{
5252
"abstract" : "Print the average of the values.",
53+
"aliases" : [
54+
"avg"
55+
],
5356
"arguments" : [
5457
{
5558
"abstract" : "The kind of average to provide.",

0 commit comments

Comments
 (0)