Skip to content

Commit 624c2bf

Browse files
authored
Add quiet flag (-q, --quiet) to LoggingOptions. (#5988)
* Add quiet flag (-q, --quiet) to LoggingOptions.
1 parent 723a592 commit 624c2bf

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

Sources/CoreCommands/Options.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ public struct LoggingOptions: ParsableArguments {
138138
/// The verbosity of informational output.
139139
@Flag(name: [.long, .customLong("vv")], help: "Increase verbosity to include debug output")
140140
public var veryVerbose: Bool = false
141+
142+
/// Whether logging output should be limited to `.error`.
143+
@Flag(name: .shortAndLong, help: "Decrease verbosity to only include error output.")
144+
public var quiet: Bool = false
141145
}
142146

143147
public struct SecurityOptions: ParsableArguments {

Sources/CoreCommands/SwiftTool.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,8 @@ extension LoggingOptions {
822822
return .info
823823
} else if self.veryVerbose {
824824
return .debug
825+
} else if self.quiet {
826+
return .error
825827
} else {
826828
return .warning
827829
}

Tests/CommandsTests/SwiftToolTests.swift

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,44 @@ final class SwiftToolTests: CommandsTestCase {
115115
XCTAssertMatch(outputStream.bytes.validDescription, .contains("info: info"))
116116
XCTAssertMatch(outputStream.bytes.validDescription, .contains("debug: debug"))
117117
}
118+
119+
do {
120+
let outputStream = BufferedOutputByteStream()
121+
let options = try GlobalOptions.parse(["--package-path", fixturePath.pathString, "--quiet"])
122+
let tool = try SwiftTool.createSwiftToolForTest(outputStream: outputStream, options: options)
123+
XCTAssertEqual(tool.logLevel, .error)
124+
125+
tool.observabilityScope.emit(error: "error")
126+
tool.observabilityScope.emit(warning: "warning")
127+
tool.observabilityScope.emit(info: "info")
128+
tool.observabilityScope.emit(debug: "debug")
129+
130+
tool.waitForObservabilityEvents(timeout: .now() + .seconds(1))
131+
132+
XCTAssertMatch(outputStream.bytes.validDescription, .contains("error: error"))
133+
XCTAssertNoMatch(outputStream.bytes.validDescription, .contains("warning: warning"))
134+
XCTAssertNoMatch(outputStream.bytes.validDescription, .contains("info: info"))
135+
XCTAssertNoMatch(outputStream.bytes.validDescription, .contains("debug: debug"))
136+
}
137+
138+
do {
139+
let outputStream = BufferedOutputByteStream()
140+
let options = try GlobalOptions.parse(["--package-path", fixturePath.pathString, "-q"])
141+
let tool = try SwiftTool.createSwiftToolForTest(outputStream: outputStream, options: options)
142+
XCTAssertEqual(tool.logLevel, .error)
143+
144+
tool.observabilityScope.emit(error: "error")
145+
tool.observabilityScope.emit(warning: "warning")
146+
tool.observabilityScope.emit(info: "info")
147+
tool.observabilityScope.emit(debug: "debug")
148+
149+
tool.waitForObservabilityEvents(timeout: .now() + .seconds(1))
150+
151+
XCTAssertMatch(outputStream.bytes.validDescription, .contains("error: error"))
152+
XCTAssertNoMatch(outputStream.bytes.validDescription, .contains("warning: warning"))
153+
XCTAssertNoMatch(outputStream.bytes.validDescription, .contains("info: info"))
154+
XCTAssertNoMatch(outputStream.bytes.validDescription, .contains("debug: debug"))
155+
}
118156
}
119157
}
120158

0 commit comments

Comments
 (0)