Skip to content

Commit 050a536

Browse files
committed
Improve ToolInfoV0 HelpCommand injection.
Signed-off-by: Ross Goldberg <[email protected]>
1 parent cd7446f commit 050a536

File tree

9 files changed

+92
-6
lines changed

9 files changed

+92
-6
lines changed

Sources/ArgumentParser/Usage/DumpHelpGenerator.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,10 @@ extension ToolInfoV0 {
5757
self.init(command: CommandInfoV0(commandStack: commandStack))
5858
// FIXME: This is a hack to inject the help command into the tool info
5959
// instead we should try to lift this into the parseable command tree
60-
var helpCommandInfo = CommandInfoV0(commandStack: [HelpCommand.self])
61-
helpCommandInfo.superCommands =
62-
(self.command.superCommands ?? []) + [self.command.commandName]
6360
self.command.subcommands =
64-
(self.command.subcommands ?? []) + [helpCommandInfo]
61+
(self.command.subcommands ?? []) + [
62+
CommandInfoV0(commandStack: commandStack + [HelpCommand.self])
63+
]
6564
}
6665
}
6766

Tests/ArgumentParserGenerateDoccReferenceTests/Snapshots/testMathDoccReference().md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,17 @@ math stats quantiles [<one-of-four>] [<custom-arg>] [<custom-deprecated-arg>] [<
207207
Show subcommand help information.
208208

209209
```
210-
math help [<subcommands>...]
210+
math help [<subcommands>...] [--version]
211211
```
212212

213213
- term **subcommands**:
214214

215215

216+
- term **--version:**
217+
218+
*Show the version.*
219+
220+
216221

217222

218223

Tests/ArgumentParserGenerateDoccReferenceTests/Snapshots/testMathMarkdownReference().md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,17 @@ math stats quantiles [<one-of-four>] [<custom-arg>] [<custom-deprecated-arg>] [<
207207
Show subcommand help information.
208208

209209
```
210-
math help [<subcommands>...]
210+
math help [<subcommands>...] [--version]
211211
```
212212

213213
**subcommands:**
214214

215215

216+
**--version:**
217+
218+
*Show the version.*
219+
220+
216221

217222

218223

Tests/ArgumentParserGenerateManualTests/Snapshots/testMathMultiPageManual().mdoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,12 @@ and
277277
.Sh SYNOPSIS
278278
.Nm
279279
.Op Ar subcommands...
280+
.Op Fl -version
280281
.Sh DESCRIPTION
281282
.Bl -tag -width 6n
282283
.It Ar subcommands...
284+
.It Fl -version
285+
Show the version.
283286
.El
284287
.Sh AUTHORS
285288
The

Tests/ArgumentParserGenerateManualTests/Snapshots/testMathSinglePageManual().mdoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ Show help information.
9393
Show subcommand help information.
9494
.Bl -tag -width 6n
9595
.It Ar subcommands...
96+
.It Fl -version
97+
Show the version.
9698
.El
9799
.El
98100
.Sh AUTHORS

Tests/ArgumentParserUnitTests/Snapshots/testMathAddDumpHelp().json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,24 @@
110110
},
111111
"shouldDisplay" : false,
112112
"valueName" : "help"
113+
},
114+
{
115+
"abstract" : "Show the version.",
116+
"isOptional" : true,
117+
"isRepeating" : false,
118+
"kind" : "flag",
119+
"names" : [
120+
{
121+
"kind" : "long",
122+
"name" : "version"
123+
}
124+
],
125+
"preferredName" : {
126+
"kind" : "long",
127+
"name" : "version"
128+
},
129+
"shouldDisplay" : true,
130+
"valueName" : "version"
113131
}
114132
],
115133
"commandName" : "help",

Tests/ArgumentParserUnitTests/Snapshots/testMathDumpHelp().json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,24 @@
724724
},
725725
"shouldDisplay" : false,
726726
"valueName" : "help"
727+
},
728+
{
729+
"abstract" : "Show the version.",
730+
"isOptional" : true,
731+
"isRepeating" : false,
732+
"kind" : "flag",
733+
"names" : [
734+
{
735+
"kind" : "long",
736+
"name" : "version"
737+
}
738+
],
739+
"preferredName" : {
740+
"kind" : "long",
741+
"name" : "version"
742+
},
743+
"shouldDisplay" : true,
744+
"valueName" : "version"
727745
}
728746
],
729747
"commandName" : "help",

Tests/ArgumentParserUnitTests/Snapshots/testMathMultiplyDumpHelp().json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,24 @@
110110
},
111111
"shouldDisplay" : false,
112112
"valueName" : "help"
113+
},
114+
{
115+
"abstract" : "Show the version.",
116+
"isOptional" : true,
117+
"isRepeating" : false,
118+
"kind" : "flag",
119+
"names" : [
120+
{
121+
"kind" : "long",
122+
"name" : "version"
123+
}
124+
],
125+
"preferredName" : {
126+
"kind" : "long",
127+
"name" : "version"
128+
},
129+
"shouldDisplay" : true,
130+
"valueName" : "version"
113131
}
114132
],
115133
"commandName" : "help",

Tests/ArgumentParserUnitTests/Snapshots/testMathStatsDumpHelp().json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,24 @@
512512
},
513513
"shouldDisplay" : false,
514514
"valueName" : "help"
515+
},
516+
{
517+
"abstract" : "Show the version.",
518+
"isOptional" : true,
519+
"isRepeating" : false,
520+
"kind" : "flag",
521+
"names" : [
522+
{
523+
"kind" : "long",
524+
"name" : "version"
525+
}
526+
],
527+
"preferredName" : {
528+
"kind" : "long",
529+
"name" : "version"
530+
},
531+
"shouldDisplay" : true,
532+
"valueName" : "version"
515533
}
516534
],
517535
"commandName" : "help",

0 commit comments

Comments
 (0)