@@ -19,10 +19,25 @@ 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
+
22
37
/// Returns the arguments that should be passed to `docc` to invoke the given plugin action.
23
38
///
24
- /// Merges the arguments provided upon initialization of the parsed arguments
25
- /// with default fallback values for required options that were not provided.
39
+ /// Merges the arguments provided upon initialization of the parsed arguments that are relevant
40
+ /// to `docc` with default fallback values for required options that were not provided.
26
41
///
27
42
/// For example, if ParsedArguments is initialized like so:
28
43
///
@@ -90,7 +105,7 @@ public struct ParsedArguments {
90
105
symbolGraphDirectoryPath: String ,
91
106
outputPath: String
92
107
) -> Arguments {
93
- var doccArguments = arguments
108
+ var doccArguments = arguments. filter ( for : . docc )
94
109
95
110
// Iterate through the flags required for the `docc` invocation
96
111
// and append any that are not already present.
@@ -170,6 +185,51 @@ public struct ParsedArguments {
170
185
]
171
186
172
187
private static let argumentsTransformers : [ ArgumentsTransforming ] = [
173
- PluginFlag . disableIndex
188
+ PluginFlag . disableIndex,
189
+ PluginFlag . extendedTypes
174
190
]
175
191
}
192
+
193
+ private extension ParsedArguments {
194
+ enum ArgumentConsumer : CaseIterable {
195
+ /// The `docc` command
196
+ case docc
197
+ /// The `swift package dump-symbol-graph` command
198
+ case dumpSymbolGraph
199
+
200
+ /// Returns the flags applicable to an `ArgumentConsumer`.
201
+ ///
202
+ /// If `flags` is `nil`, this `ArgumentConsumer` is assumed to
203
+ /// consume all flags not consumed by any of the other `ArgumentConsumer`s.
204
+ var flags : [ PluginFlag ] ? {
205
+ switch self {
206
+ case . dumpSymbolGraph:
207
+ return [
208
+ PluginFlag . extendedTypes
209
+ ]
210
+ case . docc:
211
+ return nil
212
+ }
213
+ }
214
+ }
215
+ }
216
+
217
+ private extension Arguments {
218
+ /// Returns the subset of arguments which are applicable to the given `consumer`.
219
+ func filter( for consumer: ParsedArguments . ArgumentConsumer ) -> Arguments {
220
+ if let flagsToInclude = consumer. flags {
221
+ return self . filter { argument in
222
+ flagsToInclude. contains ( where: { flag in
223
+ flag. parsedValues. contains ( argument)
224
+ } )
225
+ }
226
+ } else {
227
+ let flagsToExclude = ParsedArguments . ArgumentConsumer. allCases. compactMap ( \. flags) . flatMap { $0 }
228
+ return self . filter { argument in
229
+ !flagsToExclude. contains ( where: { flag in
230
+ flag. parsedValues. contains ( argument)
231
+ } )
232
+ }
233
+ }
234
+ }
235
+ }
0 commit comments