Procházet zdrojové kódy

Auto create missing file if it doesn't exist

Tim Jones před 1 měsícem
rodič
revize
67e0997f89

+ 9 - 4
Shared.Rcl/CliBootstrap.cs

@@ -63,11 +63,16 @@ public static class CliBootstrap
             ? yamlDir
             ? yamlDir
             : Path.Combine(appBasePath, yamlDir);
             : Path.Combine(appBasePath, yamlDir);
         
         
-        if (!Directory.Exists(resolvedYamlDir))
-            throw new DirectoryNotFoundException(
-                $"YAML directory not found: {resolvedYamlDir}");
-        
+
+        Directory.CreateDirectory(resolvedYamlDir);
+
         var fullYamlPath = Path.Combine(resolvedYamlDir, yamlFile);
         var fullYamlPath = Path.Combine(resolvedYamlDir, yamlFile);
+
+        if (!File.Exists(fullYamlPath))
+        {
+            await File.WriteAllTextAsync(fullYamlPath, "");
+        }
+        
         var collection = new YamlResourceCollection(
         var collection = new YamlResourceCollection(
             fullYamlPath,
             fullYamlPath,
             new PhysicalTextFileStore(),
             new PhysicalTextFileStore(),

+ 0 - 2
Tests/EndToEnd/AccessPointE2ETests.cs

@@ -27,8 +27,6 @@ public class AccessPointYamlE2ETests(TempYamlCliFixture fs, ITestOutputHelper ou
     [Fact]
     [Fact]
     public async Task accesspoints_cli_workflow_test()
     public async Task accesspoints_cli_workflow_test()
     {
     {
-        await File.WriteAllTextAsync(Path.Combine(fs.Root, "config.yaml"), "");
-
         // Add AP
         // Add AP
         var (output, yaml) = await ExecuteAsync("accesspoints", "add", "ap01");
         var (output, yaml) = await ExecuteAsync("accesspoints", "add", "ap01");
         Assert.Equal("Access Point 'ap01' added.\n", output);
         Assert.Equal("Access Point 'ap01' added.\n", output);