فهرست منبع

Merge pull request #112 from Timmoth/config-path-location

configurable config location
Tim Jones 1 ماه پیش
والد
کامیت
2e37898061
3فایلهای تغییر یافته به همراه20 افزوده شده و 15 حذف شده
  1. 10 6
      RackPeek.Web.Viewer/Program.cs
  2. 1 1
      RackPeek.Web/Program.cs
  3. 9 8
      RackPeek/Program.cs

+ 10 - 6
RackPeek.Web.Viewer/Program.cs

@@ -7,7 +7,6 @@ using RackPeek.Domain.Resources;
 using RackPeek.Domain.Resources.Hardware;
 using RackPeek.Domain.Resources.Services;
 using RackPeek.Domain.Resources.SystemResources;
-using RackPeek.Yaml;
 
 namespace RackPeek.Web.Viewer;
 
@@ -22,17 +21,22 @@ public class Program
         var services = builder.Services;
         builder.Services.AddScoped(sp =>
             new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
-        
+
         builder.Services.AddScoped<ITextFileStore, WasmTextFileStore>();
 
         var resources = new ResourceCollection();
         builder.Services.AddSingleton(resources);
+
+        var yamlDir = builder.Configuration.GetValue<string>("RPK_YAML_DIR") ?? "config";
+        var yamlFilePath = $"{yamlDir}/config.yaml";
+
         builder.Services.AddScoped<IResourceCollection>(sp =>
             new YamlResourceCollection(
-                "config/config.yaml",
+                yamlFilePath,
                 sp.GetRequiredService<ITextFileStore>(),
                 sp.GetRequiredService<ResourceCollection>()));
-        
+
+
         services.AddScoped<IHardwareRepository, YamlHardwareRepository>();
         services.AddScoped<ISystemRepository, YamlSystemRepository>();
         services.AddScoped<IServiceRepository, YamlServiceRepository>();
@@ -40,9 +44,9 @@ public class Program
 
         builder.Services.AddCommands();
         builder.Services.AddScoped<IConsoleEmulator, ConsoleEmulator>();
-        
+
         builder.Services.AddUseCases();
-        
+
         builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
 
         await builder.Build().RunAsync();

+ 1 - 1
RackPeek.Web/Program.cs

@@ -23,7 +23,7 @@ public class Program
             builder.Configuration
         );
 
-        var yamlDir = "./config";
+        var yamlDir = builder.Configuration.GetValue<string>("RPK_YAML_DIR") ?? "./config";
         var yamlFileName = "config.yaml";
 
         var basePath = Directory.GetCurrentDirectory();

+ 9 - 8
RackPeek/Program.cs

@@ -11,23 +11,24 @@ public static class Program
     public static async Task<int> Main(string[] args)
     {
         // Configuration
-        var configuration = new ConfigurationBuilder()
-            .SetBasePath(Directory.GetCurrentDirectory())
-            .AddJsonFile("appsettings.json", true)
+        var configuration = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory())
+            .AddJsonFile("appsettings.json", optional: true)
             .Build();
 
-        // DI
+        var yamlDir = configuration.GetValue<string>("RPK_YAML_DIR") ?? "./config";
+
+// DI
         var services = new ServiceCollection();
-        await CliBootstrap.RegisterInternals(services, configuration, "./config", "config.yaml");
+        await CliBootstrap.RegisterInternals(services, configuration, yamlDir, "config.yaml");
+
         services.AddLogging(configure =>
-            configure
-                .AddSimpleConsole(opts => { opts.TimestampFormat = "yyyy-MM-dd HH:mm:ss "; }));
+            configure.AddSimpleConsole(opts => { opts.TimestampFormat = "yyyy-MM-dd HH:mm:ss "; }));
 
         var registrar = new TypeRegistrar(services.BuildServiceProvider());
         var app = new CommandApp(registrar);
 
         CliBootstrap.BuildApp(app);
-        
+
         return await app.RunAsync(args);
     }
 }