51 lines
1.1 KiB
Swift
51 lines
1.1 KiB
Swift
import ArgumentParser
|
|
import CliClient
|
|
import Logging
|
|
import Models
|
|
import MQTTNIO
|
|
|
|
extension Application {
|
|
|
|
struct SharedOptions: ParsableArguments {
|
|
@Option(
|
|
name: [.short, .customLong("env-file")],
|
|
help: "A file path to an env file."
|
|
)
|
|
var envFile: String?
|
|
|
|
@Option(
|
|
name: [.short, .customLong("log-level")],
|
|
help: "Set the logging level."
|
|
)
|
|
var logLevel: LogLevelContainer?
|
|
|
|
@Option(
|
|
name: [.short, .long],
|
|
help: "Set the MQTT connecition version."
|
|
)
|
|
var version: String?
|
|
|
|
func envVarsRequest(logger: Logger?) -> CliClient.EnvVarsRequest {
|
|
.init(envFilePath: envFile, logger: logger, version: version)
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
/// A container type for making `Logger.Level` into a type
|
|
/// that can be parsed as a command line argument. This is
|
|
/// to suppress warnings vs. having `Logger.Level` adopt the
|
|
/// protocol.
|
|
@_spi(Internal)
|
|
public struct LogLevelContainer: ExpressibleByArgument {
|
|
public let logLevel: Logger.Level?
|
|
|
|
public init?(argument: String) {
|
|
self.logLevel = .init(rawValue: argument.lowercased())
|
|
}
|
|
|
|
public func callAsFunction() -> Logger.Level? {
|
|
logLevel
|
|
}
|
|
}
|