feat: Beginning to refactor cli-client

This commit is contained in:
2024-12-13 23:00:40 -05:00
parent 3f56dda568
commit b5afc77428
12 changed files with 479 additions and 25 deletions

View File

@@ -0,0 +1,27 @@
import Constants
import Dependencies
import Foundation
import ShellClient
public struct LoggingOptions: Equatable, Sendable {
public let commandName: String
public let logLevel: Logger.Level
public init(commandName: String, logLevel: Logger.Level) {
self.commandName = commandName
self.logLevel = logLevel
}
@discardableResult
public func withLogger<T>(
operation: @Sendable @escaping () async throws -> T
) async rethrows -> T {
try await withDependencies {
$0.logger = .init(label: "\(Constants.executableName)")
$0.logger.logLevel = logLevel
$0.logger[metadataKey: "command"] = "\(commandName.blue)"
} operation: {
try await operation()
}
}
}