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:
50
Sources/DewPointController/SharedOptions.swift
Normal file
50
Sources/DewPointController/SharedOptions.swift
Normal file
@@ -0,0 +1,50 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user