feat: More cli client tests and documentation.
All checks were successful
CI / Run Tests (push) Successful in 4m57s
All checks were successful
CI / Run Tests (push) Successful in 4m57s
This commit is contained in:
@@ -34,12 +34,23 @@ public struct CliClient {
|
||||
|
||||
/// Represents the parameters needed to create an `MQTTClient`.
|
||||
///
|
||||
///
|
||||
public struct ClientRequest: Sendable {
|
||||
|
||||
/// The environment variables used to create the client.
|
||||
public let environment: EnvVars
|
||||
|
||||
/// The event loop group for the client.
|
||||
public let eventLoopGroup: MultiThreadedEventLoopGroup
|
||||
|
||||
/// A logger to use with the client.
|
||||
public let logger: Logger?
|
||||
|
||||
/// Create a new client request.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - environment: The environment variables to use.
|
||||
/// - eventLoopGroup: The event loop group to use on the client.
|
||||
/// - logger: An optional logger to use on the client.
|
||||
public init(
|
||||
environment: EnvVars,
|
||||
eventLoopGroup: MultiThreadedEventLoopGroup,
|
||||
@@ -122,11 +133,10 @@ extension EnvVars {
|
||||
@Dependency(\.environment) var environment
|
||||
|
||||
let defaultEnvVars = EnvVars()
|
||||
let encoder = environment.jsonEncoder()
|
||||
let decoder = environment.jsonDecoder()
|
||||
let coders = environment.coders()
|
||||
|
||||
let defaultEnvDict = (try? encoder.encode(defaultEnvVars))
|
||||
.flatMap { try? decoder.decode([String: String].self, from: $0) }
|
||||
let defaultEnvDict = (try? coders.encode(defaultEnvVars))
|
||||
.flatMap { try? coders.decode([String: String].self, from: $0) }
|
||||
?? [:]
|
||||
|
||||
let dotEnvDict = try await environment.dotEnvDict(path: dotEnvFile)
|
||||
@@ -135,7 +145,7 @@ extension EnvVars {
|
||||
.merging(dotEnvDict, uniquingKeysWith: { $1 })
|
||||
|
||||
var envVars = (try? JSONSerialization.data(withJSONObject: envVarsDict))
|
||||
.flatMap { try? decoder.decode(EnvVars.self, from: $0) }
|
||||
.flatMap { try? coders.decode(EnvVars.self, from: $0) }
|
||||
?? defaultEnvVars
|
||||
|
||||
if let version {
|
||||
@@ -162,7 +172,7 @@ public extension MQTTClient {
|
||||
eventLoopGroupProvider: .shared(eventLoopGroup),
|
||||
logger: logger,
|
||||
configuration: .init(
|
||||
version: .parseOrDefualt(string: envVars.version),
|
||||
version: .parseOrDefault(string: envVars.version),
|
||||
disablePing: false,
|
||||
userName: envVars.userName,
|
||||
password: envVars.password
|
||||
@@ -171,10 +181,11 @@ public extension MQTTClient {
|
||||
}
|
||||
}
|
||||
|
||||
extension MQTTClient.Version {
|
||||
@_spi(Internal)
|
||||
public extension MQTTClient.Version {
|
||||
static let `default` = Self.v3_1_1
|
||||
|
||||
static func parseOrDefualt(string: String?) -> Self {
|
||||
static func parseOrDefault(string: String?) -> Self {
|
||||
guard let string, let value = Self(string: string) else {
|
||||
return .default
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user