Skip to content

Commit cc5ad95

Browse files
committed
Adds aliases to the dump-help output.
- Closes #812.
1 parent e905148 commit cc5ad95

File tree

9 files changed

+75
-0
lines changed

9 files changed

+75
-0
lines changed

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: 5 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
7983
self.abstract = abstract.nonEmpty
8084
self.discussion = discussion.nonEmpty
8185

@@ -89,6 +93,7 @@ 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.decode([String].self, forKey: .aliases)
9297
self.abstract = try container.decodeIfPresent(
9398
String.self, forKey: .abstract)
9499
self.discussion = try container.decodeIfPresent(

Tests/ArgumentParserUnitTests/Snapshots/testADumpHelp().json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{
22
"command" : {
3+
"aliases" : [
4+
5+
],
36
"arguments" : [
47
{
58
"allValues" : [
@@ -179,6 +182,9 @@
179182
"subcommands" : [
180183
{
181184
"abstract" : "Show subcommand help information.",
185+
"aliases" : [
186+
187+
],
182188
"arguments" : [
183189
{
184190
"isOptional" : true,

Tests/ArgumentParserUnitTests/Snapshots/testBDumpHelp().json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{
22
"command" : {
3+
"aliases" : [
4+
5+
],
36
"arguments" : [
47
{
58
"isOptional" : true,
@@ -68,6 +71,9 @@
6871
"subcommands" : [
6972
{
7073
"abstract" : "Show subcommand help information.",
74+
"aliases" : [
75+
76+
],
7177
"arguments" : [
7278
{
7379
"isOptional" : true,

Tests/ArgumentParserUnitTests/Snapshots/testCDumpHelp().json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{
22
"command" : {
3+
"aliases" : [
4+
5+
],
36
"arguments" : [
47
{
58
"abstract" : "A color to select.",
@@ -202,6 +205,9 @@
202205
"subcommands" : [
203206
{
204207
"abstract" : "Show subcommand help information.",
208+
"aliases" : [
209+
210+
],
205211
"arguments" : [
206212
{
207213
"isOptional" : true,

Tests/ArgumentParserUnitTests/Snapshots/testMathAddDumpHelp().json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{
22
"command" : {
33
"abstract" : "Print the sum of the values.",
4+
"aliases" : [
5+
6+
],
47
"arguments" : [
58
{
69
"abstract" : "Use hexadecimal notation for the result.",
@@ -82,6 +85,9 @@
8285
"subcommands" : [
8386
{
8487
"abstract" : "Show subcommand help information.",
88+
"aliases" : [
89+
90+
],
8591
"arguments" : [
8692
{
8793
"isOptional" : true,

Tests/ArgumentParserUnitTests/Snapshots/testMathDumpHelp().json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{
22
"command" : {
33
"abstract" : "A utility for performing maths.",
4+
"aliases" : [
5+
6+
],
47
"arguments" : [
58
{
69
"abstract" : "Show the version.",
@@ -50,6 +53,9 @@
5053
"subcommands" : [
5154
{
5255
"abstract" : "Print the sum of the values.",
56+
"aliases" : [
57+
58+
],
5359
"arguments" : [
5460
{
5561
"abstract" : "Use hexadecimal notation for the result.",
@@ -134,6 +140,9 @@
134140
},
135141
{
136142
"abstract" : "Print the product of the values.",
143+
"aliases" : [
144+
"mul"
145+
],
137146
"arguments" : [
138147
{
139148
"abstract" : "Use hexadecimal notation for the result.",
@@ -218,6 +227,9 @@
218227
},
219228
{
220229
"abstract" : "Calculate descriptive statistics.",
230+
"aliases" : [
231+
232+
],
221233
"arguments" : [
222234
{
223235
"abstract" : "Show the version.",
@@ -267,6 +279,9 @@
267279
"subcommands" : [
268280
{
269281
"abstract" : "Print the average of the values.",
282+
"aliases" : [
283+
"avg"
284+
],
270285
"arguments" : [
271286
{
272287
"abstract" : "The kind of average to provide.",
@@ -363,6 +378,9 @@
363378
},
364379
{
365380
"abstract" : "Print the standard deviation of the values.",
381+
"aliases" : [
382+
383+
],
366384
"arguments" : [
367385
{
368386
"abstract" : "A group of floating-point values to operate on.",
@@ -425,6 +443,9 @@
425443
},
426444
{
427445
"abstract" : "Print the quantiles of the values (TBD).",
446+
"aliases" : [
447+
448+
],
428449
"arguments" : [
429450
{
430451
"completionKind" : {
@@ -726,6 +747,9 @@
726747
},
727748
{
728749
"abstract" : "Show subcommand help information.",
750+
"aliases" : [
751+
752+
],
729753
"arguments" : [
730754
{
731755
"isOptional" : true,

Tests/ArgumentParserUnitTests/Snapshots/testMathMultiplyDumpHelp().json

Lines changed: 6 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.",
@@ -82,6 +85,9 @@
8285
"subcommands" : [
8386
{
8487
"abstract" : "Show subcommand help information.",
88+
"aliases" : [
89+
90+
],
8591
"arguments" : [
8692
{
8793
"isOptional" : true,

Tests/ArgumentParserUnitTests/Snapshots/testMathStatsDumpHelp().json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{
22
"command" : {
33
"abstract" : "Calculate descriptive statistics.",
4+
"aliases" : [
5+
6+
],
47
"arguments" : [
58
{
69
"abstract" : "Show the version.",
@@ -50,6 +53,9 @@
5053
"subcommands" : [
5154
{
5255
"abstract" : "Print the average of the values.",
56+
"aliases" : [
57+
"avg"
58+
],
5359
"arguments" : [
5460
{
5561
"abstract" : "The kind of average to provide.",
@@ -146,6 +152,9 @@
146152
},
147153
{
148154
"abstract" : "Print the standard deviation of the values.",
155+
"aliases" : [
156+
157+
],
149158
"arguments" : [
150159
{
151160
"abstract" : "A group of floating-point values to operate on.",
@@ -208,6 +217,9 @@
208217
},
209218
{
210219
"abstract" : "Print the quantiles of the values (TBD).",
220+
"aliases" : [
221+
222+
],
211223
"arguments" : [
212224
{
213225
"completionKind" : {
@@ -504,6 +516,9 @@
504516
},
505517
{
506518
"abstract" : "Show subcommand help information.",
519+
"aliases" : [
520+
521+
],
507522
"arguments" : [
508523
{
509524
"isOptional" : true,

0 commit comments

Comments
 (0)