feat: Moves logging setup and generate-json for the create command to cli-client module.

This commit is contained in:
2024-12-12 11:16:22 -05:00
parent ce6eb3ec2f
commit 7b30b78b67
14 changed files with 449 additions and 230 deletions

View File

@@ -1,4 +1,5 @@
import ArgumentParser
import CliClient
struct BasicGlobalOptions: ParsableArguments {
@Flag(
@@ -55,3 +56,21 @@ struct GlobalOptions: ParsableArguments {
}
}
extension GlobalOptions {
func loggingOptions(commandName: String) -> CliClient.LoggingOptions {
.init(
commandName: commandName,
logLevel: .init(globals: basic, quietOnlyPlaybook: quietOnlyPlaybook)
)
}
}
extension BasicGlobalOptions {
func loggingOptions(commandName: String) -> CliClient.LoggingOptions {
.init(
commandName: commandName,
logLevel: .init(globals: self, quietOnlyPlaybook: false)
)
}
}

View File

@@ -1,7 +1,5 @@
import Dependencies
import Logging
// TODO: Move some of this to the cli-client module.
extension Logger.Level {
/// Set the log level based on the user's options supplied.
@@ -22,34 +20,3 @@ extension Logger.Level {
self = .info
}
}
func withSetupLogger(
commandName: String,
globals: BasicGlobalOptions,
quietOnlyPlaybook: Bool = false,
dependencies setupDependencies: (inout DependencyValues) -> Void = { _ in },
operation: @escaping () async throws -> Void
) async rethrows {
try await withDependencies {
$0.logger = .init(label: "\("hpa".yellow)")
$0.logger.logLevel = .init(globals: globals, quietOnlyPlaybook: quietOnlyPlaybook)
$0.logger[metadataKey: "command"] = "\(commandName.blue)"
} operation: {
try await operation()
}
}
func withSetupLogger(
commandName: String,
globals: GlobalOptions,
dependencies setupDependencies: (inout DependencyValues) -> Void = { _ in },
operation: @escaping () async throws -> Void
) async rethrows {
try await withSetupLogger(
commandName: commandName,
globals: globals.basic,
quietOnlyPlaybook: globals.quietOnlyPlaybook,
dependencies: setupDependencies,
operation: operation
)
}