private static async Task ExecuteAsync(OutputContext output, DirectoryInfo directory) { var opulenceFilePath = DirectorySearch.AscendingSearch(directory.FullName, "opulence.json"); if (opulenceFilePath != null) { output.WriteInfoLine($"found 'opulence.json' at '{Path.GetDirectoryName(opulenceFilePath)}'"); return; } output.WriteInfoLine("locating nearest sln file"); var solutionFilePath = DirectorySearch.AscendingWildcardSearch(directory.FullName, "*.sln").FirstOrDefault()?.FullName; if (opulenceFilePath == null && solutionFilePath != null && Confirm(output, $"use '{Path.GetDirectoryName(solutionFilePath)}' as root?")) { opulenceFilePath = Path.Combine(Path.GetDirectoryName(solutionFilePath) !, "opulence.json"); } if (opulenceFilePath == null && Confirm(output, "use project directory as root?")) { opulenceFilePath = Path.Combine(directory.FullName, "opulence.json"); } if (opulenceFilePath == null) { throw new CommandException("cannot determine root directory"); } var config = new OpulenceConfig() { Container = new ContainerConfig() { Registry = new RegistryConfig(), } }; while (true) { output.WriteAlways("entry the container registry hostname (ex: example.azurecr.io): "); var line = Console.ReadLine(); output.WriteAlwaysLine(string.Empty); if (!string.IsNullOrEmpty(line)) { config.Container.Registry.Hostname = line.Trim(); break; } } using var stream = File.OpenWrite(opulenceFilePath); await JsonSerializer.SerializeAsync(stream, config, new JsonSerializerOptions() { WriteIndented = true, }); output.WriteInfo($"initialized opulence config at '{opulenceFilePath}'"); }