Skip to content

Commit 9c9a23d

Browse files
committed
Allow config file write to disk
1 parent 81fa9db commit 9c9a23d

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/ACMEServer.ConfigCLI/ConfigCLI.cs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,34 @@ public async Task RunAsync()
2020
}
2121

2222
Console.Clear();
23-
DumpConfig();
23+
FinalizeProcess();
2424
}
2525

26-
private void DumpConfig()
26+
private void FinalizeProcess()
2727
{
28-
var config = JsonSerializer.Serialize(ConfigRoot, new JsonSerializerOptions()
28+
var configJson = JsonSerializer.Serialize(ConfigRoot, new JsonSerializerOptions()
2929
{
3030
WriteIndented = true,
3131
PropertyNamingPolicy = null,
3232
DictionaryKeyPolicy = null
3333
});
3434

35-
Console.WriteLine(config);
35+
Console.WriteLine("Your configuration:");
36+
Console.WriteLine(configJson);
37+
38+
var saveToFile = CLIPrompt.Bool("Do you want to save the configuration to a file?");
39+
if (saveToFile)
40+
{
41+
var filePath = CLIPrompt.String("Enter the file path to save the configuration [./appsettings.Production.json]:");
42+
if (string.IsNullOrWhiteSpace(filePath))
43+
{
44+
var assemblyPath = AppContext.BaseDirectory;
45+
filePath = Path.Combine(assemblyPath, "appsettings.Production.json");
46+
}
47+
48+
File.WriteAllText(filePath, configJson);
49+
Console.WriteLine($"Configuration saved to {filePath}");
50+
}
3651
}
3752

3853
internal void PushScreen(CLIScreen screen)

0 commit comments

Comments
 (0)