30 lines
757 B
Swift
30 lines
757 B
Swift
import Dependencies
|
|
import Logging
|
|
import ShellClient
|
|
|
|
// TODO: Remove.
|
|
public extension CliClient {
|
|
|
|
@discardableResult
|
|
func withLogger<T>(
|
|
_ options: LoggingOptions,
|
|
operation: @Sendable @escaping () async throws -> T
|
|
) async rethrows -> T {
|
|
try await Self.withLogger(options, operation: operation)
|
|
}
|
|
|
|
@discardableResult
|
|
static func withLogger<T>(
|
|
_ options: LoggingOptions,
|
|
operation: @Sendable @escaping () async throws -> T
|
|
) async rethrows -> T {
|
|
try await withDependencies {
|
|
$0.logger = .init(label: "\(Constants.executableName)")
|
|
$0.logger.logLevel = options.logLevel
|
|
$0.logger[metadataKey: "command"] = "\(options.commandName.blue)"
|
|
} operation: {
|
|
try await operation()
|
|
}
|
|
}
|
|
}
|