Integrated the AppOptions options to the"init(name: archivesPath: )" initialisation function for the AppBuilder type in the library target.

This commit is contained in:
Javier Cicchelli 2025-03-26 00:31:16 +01:00
parent f9fc29c8da
commit b13ba625f4
3 changed files with 26 additions and 20 deletions

View File

@ -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)

View File

@ -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
}

View File

@ -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