File tree Expand file tree Collapse file tree 4 files changed +51
-4
lines changed
Tests/ArgumentParserUnitTests Expand file tree Collapse file tree 4 files changed +51
-4
lines changed Original file line number Diff line number Diff line change 31
31
@propertyWrapper
32
32
public struct OptionGroup < Value: ParsableArguments > : Decodable , ParsedWrapper {
33
33
internal var _parsedValue : Parsed < Value >
34
+ internal var _hidden : Bool ?
34
35
35
36
internal init ( _parsedValue: Parsed < Value > ) {
36
37
self . _parsedValue = _parsedValue
@@ -84,7 +85,17 @@ extension OptionGroup: CustomStringConvertible {
84
85
case . value( let v) :
85
86
return String ( describing: v)
86
87
case . definition:
88
+ if let hidden = _hidden {
89
+ return " OptionGroup(*definition*) _hidden: \( hidden) "
90
+ }
87
91
return " OptionGroup(*definition*) "
88
92
}
89
93
}
90
94
}
95
+
96
+ extension OptionGroup {
97
+ public init ( _hidden: Bool ) {
98
+ self . init ( )
99
+ self . _hidden = _hidden
100
+ }
101
+ }
Original file line number Diff line number Diff line change @@ -213,7 +213,7 @@ protocol ArgumentSetProvider {
213
213
}
214
214
215
215
extension ArgumentSet {
216
- init ( _ type: ParsableArguments . Type ) {
216
+ init ( _ type: ParsableArguments . Type , creatingHelp : Bool = false ) {
217
217
218
218
#if DEBUG
219
219
do {
@@ -228,6 +228,10 @@ extension ArgumentSet {
228
228
. compactMap { child in
229
229
guard var codingKey = child. label else { return nil }
230
230
231
+ if creatingHelp {
232
+ guard !String( describing: child. value) . contains ( " _hidden: true " ) else { return nil }
233
+ }
234
+
231
235
if let parsed = child. value as? ArgumentSetProvider {
232
236
// Property wrappers have underscore-prefixed names
233
237
codingKey = String ( codingKey. first == " _ "
Original file line number Diff line number Diff line change @@ -147,13 +147,13 @@ internal struct HelpGenerator {
147
147
148
148
var commandsToShowHelp = [ ParsableCommand . Type] ( )
149
149
if let commandType = commandStack. last, !commandType. includeSuperCommandInHelp {
150
- commandsToShowHelp. append ( commandType)
150
+ commandsToShowHelp. append ( commandType)
151
151
} else {
152
- commandsToShowHelp = commandStack
152
+ commandsToShowHelp = commandStack
153
153
}
154
154
155
155
for commandType in commandsToShowHelp {
156
- let args = Array ( ArgumentSet ( commandType) )
156
+ let args = Array ( ArgumentSet ( commandType, creatingHelp : true ) )
157
157
158
158
var i = 0
159
159
while i < args. count {
Original file line number Diff line number Diff line change @@ -475,4 +475,36 @@ extension HelpGenerationTests {
475
475
476
476
""" )
477
477
}
478
+
479
+ struct optionsToHide : ParsableArguments {
480
+ @Flag ( help: " Verbose " )
481
+ var verbose : Bool = false
482
+
483
+ @Option ( help: " Custom Name " )
484
+ var customName : String ?
485
+ }
486
+
487
+ struct HideDriver : ParsableCommand {
488
+ static let configuration = CommandConfiguration ( commandName: " driver " , abstract: " Demo hiding option groups " )
489
+
490
+ @OptionGroup ( _hidden: true )
491
+ var hideMe : optionsToHide
492
+
493
+ @Option ( help: " Time to wait before timeout (in seconds) " )
494
+ var timeout : Int ?
495
+ }
496
+
497
+ func testHidingOptionGroup( ) throws {
498
+ AssertHelp ( for: HideDriver . self, equals: """
499
+ OVERVIEW: Demo hiding option groups
500
+
501
+ USAGE: driver [--verbose] [--custom-name <custom-name>] [--timeout <timeout>]
502
+
503
+ OPTIONS:
504
+ --timeout <timeout> Time to wait before timeout (in seconds)
505
+ -h, --help Show help information.
506
+
507
+ """
508
+ )
509
+ }
478
510
}
You can’t perform that action at this time.
0 commit comments