@@ -69,6 +69,12 @@ struct TargetNotFoundDiagnostic: DiagnosticData {
69
69
70
70
private class ToolWorkspaceDelegate : WorkspaceDelegate {
71
71
72
+ private let options : ToolOptions
73
+
74
+ init ( toolOptions: ToolOptions ) {
75
+ options = toolOptions
76
+ }
77
+
72
78
func packageGraphWillLoad(
73
79
currentGraph: PackageGraph ,
74
80
dependencies: AnySequence < ManagedDependency > ,
@@ -77,39 +83,53 @@ private class ToolWorkspaceDelegate: WorkspaceDelegate {
77
83
}
78
84
79
85
func fetchingWillBegin( repository: String ) {
80
- print ( " Fetching \( repository) " )
86
+ if !options. shouldMuteOutput {
87
+ print ( " Fetching \( repository) " )
88
+ }
81
89
}
82
90
83
91
func fetchingDidFinish( repository: String , diagnostic: Diagnostic ? ) {
84
92
}
85
93
86
94
func repositoryWillUpdate( _ repository: String ) {
87
- print ( " Updating \( repository) " )
95
+ if !options. shouldMuteOutput {
96
+ print ( " Updating \( repository) " )
97
+ }
88
98
}
89
99
90
100
func repositoryDidUpdate( _ repository: String ) {
91
101
}
92
102
93
103
func dependenciesUpToDate( ) {
94
- print ( " Everything is already up-to-date " )
104
+ if !options. shouldMuteOutput {
105
+ print ( " Everything is already up-to-date " )
106
+ }
95
107
}
96
108
97
109
func cloning( repository: String ) {
98
- print ( " Cloning \( repository) " )
110
+ if !options. shouldMuteOutput {
111
+ print ( " Cloning \( repository) " )
112
+ }
99
113
}
100
114
101
115
func checkingOut( repository: String , atReference reference: String , to path: AbsolutePath ) {
102
116
// FIXME: This is temporary output similar to old one, we will need to figure
103
117
// out better reporting text.
104
- print ( " Resolving \( repository) at \( reference) " )
118
+ if !options. shouldMuteOutput {
119
+ print ( " Resolving \( repository) at \( reference) " )
120
+ }
105
121
}
106
122
107
123
func removing( repository: String ) {
108
- print ( " Removing \( repository) " )
124
+ if !options. shouldMuteOutput {
125
+ print ( " Removing \( repository) " )
126
+ }
109
127
}
110
128
111
129
func warning( message: String ) {
112
- print ( " warning: " + message)
130
+ if !options. shouldMuteOutput {
131
+ print ( " warning: " + message)
132
+ }
113
133
}
114
134
115
135
func managedDependenciesDidUpdate( _ dependencies: AnySequence < ManagedDependency > ) {
@@ -202,7 +222,7 @@ public class SwiftTool<Options: ToolOptions> {
202
222
let interruptHandler : InterruptHandler
203
223
204
224
/// The diagnostics engine.
205
- let diagnostics = DiagnosticsEngine ( handlers : [ SwiftTool . diagnosticsHandler ] )
225
+ let diagnostics : DiagnosticsEngine
206
226
207
227
/// The execution status of the tool.
208
228
var executionStatus : ExecutionStatus = . success
@@ -325,8 +345,9 @@ public class SwiftTool<Options: ToolOptions> {
325
345
326
346
var options = Options ( )
327
347
try binder. fill ( parseResult: result, into: & options)
328
-
348
+ diagnostics = DiagnosticsEngine ( handlers : [ setupDiagnosticsHandler ( with : options ) ] )
329
349
self . options = options
350
+
330
351
// Honor package-path option is provided.
331
352
if let packagePath = options. packagePath ?? options. chdir {
332
353
// FIXME: This should be an API which takes AbsolutePath and maybe
@@ -368,7 +389,7 @@ public class SwiftTool<Options: ToolOptions> {
368
389
self . buildPath = getEnvBuildPath ( ) ??
369
390
customBuildPath ??
370
391
( packageRoot ?? localFileSystem. currentWorkingDirectory!) . appending ( component: " .build " )
371
-
392
+
372
393
if options. chdir != nil {
373
394
diagnostics. emit ( data: ChdirDeprecatedDiagnostic ( ) )
374
395
}
@@ -394,7 +415,8 @@ public class SwiftTool<Options: ToolOptions> {
394
415
if let workspace = _workspace {
395
416
return workspace
396
417
}
397
- let delegate = ToolWorkspaceDelegate ( )
418
+ let delegate = ToolWorkspaceDelegate ( toolOptions: options)
419
+
398
420
let rootPackage = try getPackageRoot ( )
399
421
let provider = GitRepositoryProvider ( processSet: processSet)
400
422
let workspace = Workspace (
@@ -431,10 +453,6 @@ public class SwiftTool<Options: ToolOptions> {
431
453
SwiftTool . exit ( with: executionStatus)
432
454
}
433
455
434
- static func diagnosticsHandler( _ diagnostic: Diagnostic ) {
435
- print ( diagnostic: diagnostic)
436
- }
437
-
438
456
/// Exit the tool with the given execution status.
439
457
private static func exit( with status: ExecutionStatus ) -> Never {
440
458
switch status {
@@ -680,6 +698,14 @@ public class SwiftTool<Options: ToolOptions> {
680
698
}
681
699
}
682
700
701
+ func setupDiagnosticsHandler( with options: ToolOptions ) -> ( Diagnostic ) -> Void {
702
+ return { diagnostic in
703
+ if !options. shouldMuteOutput || diagnostic. behavior == . error {
704
+ print ( diagnostic: diagnostic)
705
+ }
706
+ }
707
+ }
708
+
683
709
/// An enum representing what subset of the package to build.
684
710
enum BuildSubset {
685
711
/// Represents the subset of all products and non-test targets.
0 commit comments