Tim Jones 1 месяц назад
Родитель
Сommit
6980359f16
3 измененных файлов с 26 добавлено и 13 удалено
  1. BIN
      .DS_Store
  2. 6 3
      RackPeek/Program.cs
  3. 20 10
      Shared.Rcl/CliBootstrap.cs

+ 6 - 3
RackPeek/Program.cs

@@ -11,13 +11,16 @@ public static class Program
     public static async Task<int> Main(string[] args)
     {
         // Configuration
-        var configuration = new ConfigurationBuilder().SetBasePath(AppContext.BaseDirectory)
+        var appBasePath = AppContext.BaseDirectory;
+
+        var configuration = new ConfigurationBuilder()
+            .SetBasePath(appBasePath)
             .AddJsonFile("appsettings.json", optional: true)
             .Build();
 
-        var yamlDir = configuration.GetValue<string>("RPK_YAML_DIR") ?? "./config";
+        var yamlDir = configuration.GetValue<string>("RPK_YAML_DIR") ?? "config";
 
-// DI
+        // DI
         var services = new ServiceCollection();
         await CliBootstrap.RegisterInternals(services, configuration, yamlDir, "config.yaml");
 

+ 20 - 10
Shared.Rcl/CliBootstrap.cs

@@ -50,19 +50,29 @@ public static class CliBootstrap
         _lastArgs = args;
         _app = app;
     }
-    public static async Task RegisterInternals(IServiceCollection services, IConfiguration configuration,
-        string yamlDir, string yamlFile)
+    public static async Task RegisterInternals(
+        IServiceCollection services,
+        IConfiguration configuration,
+        string yamlDir,
+        string yamlFile)
     {
         services.AddSingleton(configuration);
+        var appBasePath = AppContext.BaseDirectory;
+
+        var resolvedYamlDir = Path.IsPathRooted(yamlDir)
+            ? yamlDir
+            : Path.Combine(appBasePath, yamlDir);
+        
+        if (!Directory.Exists(resolvedYamlDir))
+            throw new DirectoryNotFoundException(
+                $"YAML directory not found: {resolvedYamlDir}");
+        
+        var fullYamlPath = Path.Combine(resolvedYamlDir, yamlFile);
+        var collection = new YamlResourceCollection(
+            fullYamlPath,
+            new PhysicalTextFileStore(),
+            new ResourceCollection());
 
-        var basePath = configuration["HardwarePath"] ?? AppContext.BaseDirectory;
-
-        // Resolve yamlDir as relative to basePath
-        var yamlPath = Path.IsPathRooted(yamlDir) ? yamlDir : Path.Combine(basePath, yamlDir);
-
-        if (!Directory.Exists(yamlPath)) throw new DirectoryNotFoundException($"YAML directory not found: {yamlPath}");
-
-        var collection = new YamlResourceCollection(Path.Combine(yamlPath, yamlFile), new PhysicalTextFileStore(), new ResourceCollection());
         await collection.LoadAsync();
         services.AddSingleton<IResourceCollection>(collection);