1010//===----------------------------------------------------------------------===//
1111
1212struct HelpCommand : ParsableCommand {
13+ enum CodingKeys : CodingKey {
14+ case subcommands
15+ case help
16+ }
17+
1318 static var configuration = CommandConfiguration (
1419 commandName: " help " ,
1520 abstract: " Show subcommand help information. " ,
@@ -23,16 +28,32 @@ struct HelpCommand: ParsableCommand {
2328 var help = false
2429
2530 private( set) var commandStack : [ ParsableCommand . Type ] = [ ]
26- private( set) var visibility : ArgumentVisibility = . default
31+ private( set) var options = HelpOptions . plain
2732
28- init ( ) { }
33+ init ( ) { }
34+
35+ init ( from decoder: Decoder ) throws {
36+ let container = try decoder. container ( keyedBy: CodingKeys . self)
37+ self . subcommands = try container. decode ( [ String ] . self, forKey: . subcommands)
38+ self . help = try container. decode ( Bool . self, forKey: . help)
39+ }
2940
41+ init (
42+ commandStack: [ ParsableCommand . Type ] ,
43+ options: HelpOptions
44+ ) {
45+ self . commandStack = commandStack
46+ self . options = options
47+ self . subcommands = commandStack. map { $0. _commandName }
48+ self . help = false
49+ }
50+
3051 mutating func run( ) throws {
3152 throw CommandError (
3253 commandStack: commandStack,
33- parserError: . helpRequested( visibility : visibility ) )
54+ parserError: . helpRequested( options : options ) )
3455 }
35-
56+
3657 mutating func buildCommandStack( with parser: CommandParser ) throws {
3758 commandStack = parser. commandStack ( for: subcommands)
3859 }
@@ -41,25 +62,7 @@ struct HelpCommand: ParsableCommand {
4162 func generateHelp( screenWidth: Int ) -> String {
4263 HelpGenerator (
4364 commandStack: commandStack,
44- visibility : visibility )
65+ options : options )
4566 . rendered ( screenWidth: screenWidth)
4667 }
47-
48- enum CodingKeys : CodingKey {
49- case subcommands
50- case help
51- }
52-
53- init ( from decoder: Decoder ) throws {
54- let container = try decoder. container ( keyedBy: CodingKeys . self)
55- self . subcommands = try container. decode ( [ String ] . self, forKey: . subcommands)
56- self . help = try container. decode ( Bool . self, forKey: . help)
57- }
58-
59- init ( commandStack: [ ParsableCommand . Type ] , visibility: ArgumentVisibility ) {
60- self . commandStack = commandStack
61- self . visibility = visibility
62- self . subcommands = commandStack. map { $0. _commandName }
63- self . help = false
64- }
6568}
0 commit comments