10
10
//===----------------------------------------------------------------------===//
11
11
12
12
struct HelpCommand : ParsableCommand {
13
+ enum CodingKeys : CodingKey {
14
+ case subcommands
15
+ case help
16
+ }
17
+
13
18
static var configuration = CommandConfiguration (
14
19
commandName: " help " ,
15
20
abstract: " Show subcommand help information. " ,
@@ -23,16 +28,32 @@ struct HelpCommand: ParsableCommand {
23
28
var help = false
24
29
25
30
private( set) var commandStack : [ ParsableCommand . Type ] = [ ]
26
- private( set) var visibility : ArgumentVisibility = . default
31
+ private( set) var options = HelpOptions . plain
27
32
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
+ }
29
40
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
+
30
51
mutating func run( ) throws {
31
52
throw CommandError (
32
53
commandStack: commandStack,
33
- parserError: . helpRequested( visibility : visibility ) )
54
+ parserError: . helpRequested( options : options ) )
34
55
}
35
-
56
+
36
57
mutating func buildCommandStack( with parser: CommandParser ) throws {
37
58
commandStack = parser. commandStack ( for: subcommands)
38
59
}
@@ -41,25 +62,7 @@ struct HelpCommand: ParsableCommand {
41
62
func generateHelp( screenWidth: Int ) -> String {
42
63
HelpGenerator (
43
64
commandStack: commandStack,
44
- visibility : visibility )
65
+ options : options )
45
66
. rendered ( screenWidth: screenWidth)
46
67
}
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
- }
65
68
}
0 commit comments