From 887aded53973e899e8c6572d2d59a18db364ff02 Mon Sep 17 00:00:00 2001 From: Ben Collins <=> Date: Wed, 3 Jul 2024 12:16:06 -0500 Subject: [PATCH] Add a "config" operator to provide an escape hatch for users to configure things that don't otherwise have an operator, similarly to the way the "host" operator is implemented in the HostBuilder --- src/Falco/ConfigBuilder.fs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Falco/ConfigBuilder.fs b/src/Falco/ConfigBuilder.fs index ab7757e..c38b381 100644 --- a/src/Falco/ConfigBuilder.fs +++ b/src/Falco/ConfigBuilder.fs @@ -9,14 +9,16 @@ type ConfigFile = | JsonFile of path : string type ConfigBuilderSpec = - { AddEnvVars : bool + { Config : IConfigurationBuilder -> IConfigurationBuilder + AddEnvVars : bool BasePath : string RequiredFiles : ConfigFile list OptionalFiles : ConfigFile list InMemory : Map } static member Empty = - { AddEnvVars = false + { Config = id + AddEnvVars = false BasePath = Directory.GetCurrentDirectory() RequiredFiles = [] OptionalFiles = [] @@ -29,6 +31,8 @@ type ConfigBuilder (args : string[]) = member _.Run(conf : ConfigBuilderSpec) = let mutable bldr = ConfigurationBuilder().SetBasePath(conf.BasePath) + conf.Config bldr |> ignore + for file in conf.RequiredFiles do match file with | IniFile file -> bldr.AddIniFile(file, optional = false, reloadOnChange = true) @@ -53,6 +57,10 @@ type ConfigBuilder (args : string[]) = bldr.Build() :> IConfiguration + [] + member _.Config (conf : ConfigBuilderSpec, fn : IConfigurationBuilder -> IConfigurationBuilder) = + { conf with Config = fn } + /// Sets the base path of the ConfigurationBuilder. [] member _.SetBasePath (conf : ConfigBuilderSpec, basePath : string) =