File tree Expand file tree Collapse file tree 3 files changed +28
-3
lines changed
Sources/ArgumentParser/Usage
ArgumentParserExampleTests Expand file tree Collapse file tree 3 files changed +28
-3
lines changed Original file line number Diff line number Diff line change @@ -213,11 +213,16 @@ internal struct HelpGenerator {
213213 optionElements. append ( . init( label: helpLabels, abstract: " Show help information. " ) )
214214 }
215215
216+ let configuration = commandStack. last!. configuration
216217 let subcommandElements : [ Section . Element ] =
217- commandStack . last! . configuration. subcommands. compactMap { command in
218+ configuration. subcommands. compactMap { command in
218219 guard command. configuration. shouldDisplay else { return nil }
220+ var label = command. _commandName
221+ if command == configuration. defaultSubcommand {
222+ label += " (default) "
223+ }
219224 return Section . Element (
220- label: command . _commandName ,
225+ label: label ,
221226 abstract: command. configuration. abstract)
222227 }
223228
Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ final class MathExampleTests: XCTestCase {
3030 -h, --help Show help information.
3131
3232 SUBCOMMANDS:
33- add Print the sum of the values.
33+ add (default) Print the sum of the values.
3434 multiply Print the product of the values.
3535 stats Calculate descriptive statistics.
3636
Original file line number Diff line number Diff line change @@ -377,4 +377,24 @@ extension HelpGenerationTests {
377377
378378 """ )
379379 }
380+
381+ struct M : ParsableCommand {
382+ }
383+ struct N : ParsableCommand {
384+ static var configuration = CommandConfiguration ( subcommands: [ M . self] , defaultSubcommand: M . self)
385+ }
386+
387+ func testHelpWithDefaultCommand( ) {
388+ AssertHelp ( for: N . self, equals: """
389+ USAGE: n <subcommand>
390+
391+ OPTIONS:
392+ -h, --help Show help information.
393+
394+ SUBCOMMANDS:
395+ m (default)
396+
397+ See 'n help <subcommand>' for detailed help.
398+ """ )
399+ }
380400}
You can’t perform that action at this time.
0 commit comments