From b13ba625f499b5360e8eff926a8787a0b4a5c172 Mon Sep 17 00:00:00 2001 From: Javier Cicchelli Date: Wed, 26 Mar 2025 00:31:16 +0100 Subject: [PATCH] Integrated the AppOptions options to the"init(name: archivesPath: )" initialisation function for the AppBuilder type in the library target. --- App/Sources/App.swift | 5 ++- .../Sources/Public/Builders/AppBuilder.swift | 33 ++++++++++--------- .../Public/Builders/AppBuilderTests.swift | 8 ++--- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/App/Sources/App.swift b/App/Sources/App.swift index 5976a69..b3bc2a7 100644 --- a/App/Sources/App.swift +++ b/App/Sources/App.swift @@ -11,7 +11,10 @@ struct App: AsyncParsableCommand { // MARK: Functions mutating func run() async throws { - let appBuilder = AppBuilder(appName: "Doxy") + let appBuilder = AppBuilder( + name: options.name, + archivesPath: options.archivesPath + ) let app = try await appBuilder(options) diff --git a/Library/Sources/Public/Builders/AppBuilder.swift b/Library/Sources/Public/Builders/AppBuilder.swift index 2b822a8..5e58656 100644 --- a/Library/Sources/Public/Builders/AppBuilder.swift +++ b/Library/Sources/Public/Builders/AppBuilder.swift @@ -1,27 +1,27 @@ import Hummingbird import Logging -/// A type that sets and builds an application that should be ready to run. +/// A type that sets and builds an application that would be ready to run in the executable target. public struct AppBuilder { // MARK: Properties - private let appName: String - private let folderArchives: String + private let name: String + private let archivesPath: String private let environment: Environment // MARK: Initialisers /// Initialises this type. /// - Parameters: - /// - appName: A name for the app to build. - /// - folderArchives: A relative path to the location of the *DocC* archive containers. + /// - name: A name for the app to build. + /// - archivesPath: A relative path to the location of the *DocC* archive containers. public init( - appName: String, - folderArchives: String = "Resources/Archives" + name: String, + archivesPath: String ) { - self.appName = appName - self.folderArchives = folderArchives + self.name = name + self.archivesPath = archivesPath self.environment = Environment() } @@ -30,7 +30,7 @@ public struct AppBuilder { /// Sets and builds a ready-to-use application. /// /// The application this function builds have the following features: - /// * proxy requests to any available *DocC* archive container in the `folderArchives` location; + /// * proxy requests to any available *DocC* archive container in the ``AppArguments/archivesPath`` location; /// * log any request to any available *DocC* archive container in the application console. /// /// - Parameter arguments: A set in input parameters used while building the application. @@ -42,8 +42,11 @@ public struct AppBuilder { return Application( router: router, configuration: .init( - address: .hostname(arguments.hostname, port: arguments.port), - serverName: appName + address: .hostname( + arguments.hostname, + port: arguments.port + ), + serverName: name ), logger: logger ) @@ -62,7 +65,7 @@ private extension AppBuilder { // MARK: Functions func logger(level: Logger.Level?) -> Logger { - var logger = Logger(label: appName) + var logger = Logger(label: name) logger.logLevel = level ?? environment.logLevel.flatMap { Logger.Level(rawValue: $0) ?? .info } @@ -76,10 +79,10 @@ private extension AppBuilder { router.addMiddleware { LogRequestsMiddleware(logger.logLevel) - DocCMiddleware(folderArchives) + DocCMiddleware(archivesPath) } - ArchiveController(folderArchives).register(to: router) + ArchiveController(archivesPath).register(to: router) return router } diff --git a/Test/Sources/Cases/Public/Builders/AppBuilderTests.swift b/Test/Sources/Cases/Public/Builders/AppBuilderTests.swift index 3e3bddd..11406fc 100644 --- a/Test/Sources/Cases/Public/Builders/AppBuilderTests.swift +++ b/Test/Sources/Cases/Public/Builders/AppBuilderTests.swift @@ -8,10 +8,6 @@ struct AppBuilderTests { // MARK: Properties - private let appBuilder = AppBuilder( - appName: "DoxyTest", - folderArchives: "Resources/Archives/Test" - ) private let arguments = TestArguments() // MARK: Route tests @@ -21,6 +17,10 @@ struct AppBuilderTests { uri: String, expects status: HTTPResponse.Status ) async throws { + let appBuilder = AppBuilder( + name: arguments.name, + archivesPath: arguments.archivesPath + ) let app = try await appBuilder(arguments) try await app.test(.router) { client in