@@ -19,21 +19,6 @@ public struct ParsedArguments {
19
19
return arguments. contains ( " --help " ) || arguments. contains ( " -h " )
20
20
}
21
21
22
- /// Returns the arguments that could be passed to `swift package dump-symbol-graph`.
23
- ///
24
- /// In practice, however we won't invoke the `dump-symbol-graph` command via the command line,
25
- /// but via the `PackagePlugin` API. Thus, these arguments have to be parsed later on and converted to
26
- /// `PackageManager.SymbolGraphOptions`.
27
- public func dumpSymbolGraphArguments( ) -> Arguments {
28
- var dumpSymbolGraphArguments = arguments. filter ( for: . dumpSymbolGraph)
29
-
30
- for argumentsTransformer in Self . argumentsTransformers {
31
- dumpSymbolGraphArguments = argumentsTransformer. transform ( dumpSymbolGraphArguments)
32
- }
33
-
34
- return dumpSymbolGraphArguments
35
- }
36
-
37
22
/// Returns the arguments that should be passed to `docc` to invoke the given plugin action.
38
23
///
39
24
/// Merges the arguments provided upon initialization of the parsed arguments that are relevant
@@ -168,8 +153,19 @@ public struct ParsedArguments {
168
153
/// Creates a new set of parsed arguments with the given arguments.
169
154
public init ( _ arguments: [ String ] ) {
170
155
self . arguments = arguments
156
+
157
+ let symbolGraphArguments = arguments. filter ( for: . dumpSymbolGraph)
158
+
159
+ self . symbolGraphArguments = ParsedArguments . ArgumentConsumer. dumpSymbolGraph. flags. filter { option in
160
+ option. parsedValues. contains ( where: symbolGraphArguments. contains)
161
+ }
171
162
}
172
163
164
+ // Build array with plugin flags that modify the symbol graph generation,
165
+ // filtering from the available custom symbol graph options those
166
+ // that correspond to the received flags
167
+ var symbolGraphArguments : [ PluginFlag ]
168
+
173
169
/// The command-line options required by the `docc` tool.
174
170
private static let requiredOptions : [ CommandLineOption ] = [
175
171
. fallbackDisplayName,
@@ -199,16 +195,16 @@ private extension ParsedArguments {
199
195
200
196
/// Returns the flags applicable to an `ArgumentConsumer`.
201
197
///
202
- /// If `flags` is `nil `, this `ArgumentConsumer` is assumed to
198
+ /// If `flags.isEmpty ` is `true `, this `ArgumentConsumer` is assumed to
203
199
/// consume all flags not consumed by any of the other `ArgumentConsumer`s.
204
- var flags : [ PluginFlag ] ? {
200
+ var flags : [ PluginFlag ] {
205
201
switch self {
206
202
case . dumpSymbolGraph:
207
203
return [
208
204
PluginFlag . extendedTypes
209
205
]
210
206
case . docc:
211
- return nil
207
+ return [ ]
212
208
}
213
209
}
214
210
}
@@ -217,14 +213,22 @@ private extension ParsedArguments {
217
213
private extension Arguments {
218
214
/// Returns the subset of arguments which are applicable to the given `consumer`.
219
215
func filter( for consumer: ParsedArguments . ArgumentConsumer ) -> Arguments {
220
- if let flagsToInclude = consumer. flags {
216
+ if !consumer. flags. isEmpty {
217
+ // If the consumer can provide a complete list of valid flags,
218
+ // we only include elements that are included in one of these flags'
219
+ // `parsedValues`, i.e. if one of these flags can be applied to the
220
+ // element.
221
+ let flagsToInclude = consumer. flags
221
222
return self . filter { argument in
222
223
flagsToInclude. contains ( where: { flag in
223
224
flag. parsedValues. contains ( argument)
224
225
} )
225
226
}
226
227
} else {
227
- let flagsToExclude = ParsedArguments . ArgumentConsumer. allCases. compactMap ( \. flags) . flatMap { $0 }
228
+ // If the consumer cannot provide a complete list of valid flags, (which
229
+ // should only happen for the `.docc` case) we return all elements
230
+ // that are not applicable to any of the other `ArgumentConsumer`s.
231
+ let flagsToExclude = ParsedArguments . ArgumentConsumer. allCases. flatMap ( \. flags)
228
232
return self . filter { argument in
229
233
!flagsToExclude. contains ( where: { flag in
230
234
flag. parsedValues. contains ( argument)
0 commit comments