@@ -24,14 +24,15 @@ public struct ParsedArguments {
24
24
/// In practice, however we won't invoke the `dump-symbol-graph` command via the command line,
25
25
/// but via the `PackagePlugin` API. Thus, these arguments have to be parsed later on and converted to
26
26
/// `PackageManager.SymbolGraphOptions`.
27
- public func dumpSymbolGraphArguments ( ) -> Arguments {
27
+ public func dumpSymbolGraphOptions ( ) -> SymbolGraphOptions {
28
28
var dumpSymbolGraphArguments = arguments. filter ( for: . dumpSymbolGraph)
29
+ var dumpSymbolGraphConfiguration = SymbolGraphOptions ( )
29
30
30
- for argumentsTransformer in Self . argumentsTransformers {
31
- dumpSymbolGraphArguments = argumentsTransformer . transform ( dumpSymbolGraphArguments)
31
+ for transformer in Self . argumentsTransformers {
32
+ transformer . transform ( arguments : & dumpSymbolGraphArguments, configuration : & dumpSymbolGraphConfiguration )
32
33
}
33
34
34
- return dumpSymbolGraphArguments
35
+ return dumpSymbolGraphConfiguration
35
36
}
36
37
37
38
/// Returns the arguments that should be passed to `docc` to invoke the given plugin action.
@@ -151,10 +152,12 @@ public struct ParsedArguments {
151
152
// Add any required options that are specific to the kind of target being built
152
153
doccArguments = targetKind. addRequiredOptions ( to: doccArguments)
153
154
155
+ var configuration : ( ) = Void ( )
156
+
154
157
// Apply any argument transformations. This allows for custom
155
158
// flags that are specific to the plugin and not built-in to `docc`.
156
- for argumentsTransformer in Self . argumentsTransformers {
157
- doccArguments = argumentsTransformer . transform ( doccArguments)
159
+ for transformer in Self . argumentsTransformers {
160
+ transformer . transform ( arguments : & doccArguments, configuration : & configuration )
158
161
}
159
162
160
163
// If we were given a catalog path, prepend it to the set of arguments.
@@ -201,7 +204,7 @@ private extension ParsedArguments {
201
204
///
202
205
/// If `flags` is `nil`, this `ArgumentConsumer` is assumed to
203
206
/// consume all flags not consumed by any of the other `ArgumentConsumer`s.
204
- var flags : [ PluginFlag ] ? {
207
+ var flags : [ FlagParser ] ? {
205
208
switch self {
206
209
case . dumpSymbolGraph:
207
210
return [
@@ -214,16 +217,29 @@ private extension ParsedArguments {
214
217
}
215
218
}
216
219
220
+ private protocol FlagParser {
221
+ var parsedValues : Set < String > { get }
222
+ }
223
+
224
+ extension PluginFlag : FlagParser { }
225
+
217
226
private extension Arguments {
218
227
/// Returns the subset of arguments which are applicable to the given `consumer`.
219
228
func filter( for consumer: ParsedArguments . ArgumentConsumer ) -> Arguments {
220
229
if let flagsToInclude = consumer. flags {
230
+ // If the consumer can provide a complete list of valid flags,
231
+ // we only include elements that are included in one of these flags'
232
+ // `parsedValues`, i.e. if one of these flags can be applied to the
233
+ // element.
221
234
return self . filter { argument in
222
235
flagsToInclude. contains ( where: { flag in
223
236
flag. parsedValues. contains ( argument)
224
237
} )
225
238
}
226
239
} else {
240
+ // If the consumer cannot provide a complete list of valid flags, (which
241
+ // should only happen for the `.docc` case) we return all elements
242
+ // that are not applicable to any of the other `ArgumentConsumer`s.
227
243
let flagsToExclude = ParsedArguments . ArgumentConsumer. allCases. compactMap ( \. flags) . flatMap { $0 }
228
244
return self . filter { argument in
229
245
!flagsToExclude. contains ( where: { flag in
0 commit comments