feat: Begins using swift argument parser and creating cli client dependency
All checks were successful
CI / Run Tests (push) Successful in 4m27s
All checks were successful
CI / Run Tests (push) Successful in 4m27s
This commit is contained in:
74
Sources/DewPointController/DebugCommand.swift
Normal file
74
Sources/DewPointController/DebugCommand.swift
Normal file
@@ -0,0 +1,74 @@
|
||||
import ArgumentParser
|
||||
import CliClient
|
||||
import CustomDump
|
||||
import Dependencies
|
||||
import DotEnv
|
||||
import Foundation
|
||||
import Logging
|
||||
import Models
|
||||
|
||||
extension Application {
|
||||
|
||||
struct Debug: AsyncParsableCommand {
|
||||
|
||||
static let configuration: CommandConfiguration = .init(
|
||||
commandName: "debug",
|
||||
abstract: "Debug the environment variables."
|
||||
)
|
||||
|
||||
@OptionGroup
|
||||
var shared: SharedOptions
|
||||
|
||||
@Flag(
|
||||
name: [.customLong("show-password")],
|
||||
help: "Don't redact the password from the console."
|
||||
)
|
||||
var showPassword: Bool = false
|
||||
|
||||
mutating func run() async throws {
|
||||
@Dependency(\.cliClient) var client
|
||||
let logger = Logger(label: "debug-command")
|
||||
|
||||
print("--------------------------")
|
||||
print("Running debug command...")
|
||||
if let envFile = shared.envFile {
|
||||
print("Reading env file: \(envFile)")
|
||||
print("--------------------------")
|
||||
} else {
|
||||
print("No env file set.")
|
||||
print("--------------------------")
|
||||
}
|
||||
|
||||
print("Loading EnvVars")
|
||||
print("--------------------------")
|
||||
let envVars = try await client.makeEnvVars(shared.envVarsRequest(logger: logger))
|
||||
printEnvVars(envVars: envVars, showPassword: showPassword)
|
||||
print("--------------------------")
|
||||
|
||||
if let logLevel = shared.logLevel, let level = logLevel() {
|
||||
print("Log Level option: \(level)")
|
||||
print("--------------------------")
|
||||
} else {
|
||||
print("Log Level option: nil")
|
||||
print("--------------------------")
|
||||
}
|
||||
}
|
||||
|
||||
private func printEnvVars(envVars: EnvVars, showPassword: Bool) {
|
||||
// show the proper password to show depending on if it exists
|
||||
// and if we should redact it or not.
|
||||
var passwordString: String?
|
||||
switch (showPassword, envVars.password) {
|
||||
case (true, .none), (_, .none):
|
||||
break
|
||||
case (true, let .some(password)):
|
||||
passwordString = password
|
||||
case (false, .some):
|
||||
passwordString = "<redacted>"
|
||||
}
|
||||
var envVars = envVars
|
||||
envVars.password = passwordString
|
||||
customDump(envVars)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user