-
-
Notifications
You must be signed in to change notification settings - Fork 64
Create .refitter settings file as part of output #859
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -105,6 +105,12 @@ public override async Task<int> ExecuteAsync(CommandContext context, Settings se | |
|
|
||
| Analytics.LogFeatureUsage(settings, refitGeneratorSettings); | ||
|
|
||
| // Generate .refitter settings file if not using existing settings file | ||
| if (string.IsNullOrWhiteSpace(settings.SettingsFilePath)) | ||
| { | ||
| await WriteRefitterSettingsFile(settings, refitGeneratorSettings); | ||
| } | ||
|
|
||
| if (refitGeneratorSettings.IncludePathMatches.Length > 0 && | ||
| generator.OpenApiDocument.Paths.Count == 0) | ||
| { | ||
|
|
@@ -831,4 +837,59 @@ private static void TryWriteLine( | |
| Console.ForegroundColor = originalColor; | ||
| } | ||
| } | ||
|
|
||
| private static async Task WriteRefitterSettingsFile(Settings settings, RefitGeneratorSettings refitGeneratorSettings) | ||
| { | ||
| var settingsFilePath = DetermineSettingsFilePath(settings); | ||
| var settingsDirectory = Path.GetDirectoryName(settingsFilePath); | ||
|
|
||
| if (!string.IsNullOrWhiteSpace(settingsDirectory) && !Directory.Exists(settingsDirectory)) | ||
| Directory.CreateDirectory(settingsDirectory); | ||
|
|
||
| var json = Serializer.Serialize(refitGeneratorSettings); | ||
| await File.WriteAllTextAsync(settingsFilePath, json); | ||
|
|
||
| if (settings.SimpleOutput) | ||
| { | ||
| Console.WriteLine($"Settings file written to: {settingsFilePath}"); | ||
| Console.WriteLine(); | ||
| } | ||
| else | ||
| { | ||
| var fileName = Path.GetFileName(settingsFilePath); | ||
| var directory = Path.GetDirectoryName(settingsFilePath) ?? ""; | ||
|
|
||
| var panel = new Panel( | ||
| $"[bold white]📄 File:[/] [cyan]{fileName}[/]\n" + | ||
| $"[bold white]📂 Directory:[/] [dim]{directory}[/]" | ||
| ) | ||
| .BorderColor(Color.Green) | ||
| .RoundedBorder() | ||
| .Header("[bold green]💾 Settings File Generated[/]") | ||
| .HeaderAlignment(Justify.Center); | ||
|
|
||
| AnsiConsole.Write(panel); | ||
| AnsiConsole.WriteLine(); | ||
| } | ||
| } | ||
|
Comment on lines
+841
to
+874
|
||
|
|
||
| private static string DetermineSettingsFilePath(Settings settings) | ||
| { | ||
| // If output path is specified and is a directory, put .refitter file there | ||
| if (!string.IsNullOrWhiteSpace(settings.OutputPath) && | ||
| settings.OutputPath != Settings.DefaultOutputPath) | ||
| { | ||
| var outputDir = settings.GenerateMultipleFiles || !string.IsNullOrWhiteSpace(settings.ContractsOutputPath) | ||
| ? settings.OutputPath | ||
| : Path.GetDirectoryName(settings.OutputPath); | ||
|
|
||
| if (!string.IsNullOrWhiteSpace(outputDir)) | ||
| { | ||
| return Path.Combine(outputDir, ".refitter"); | ||
| } | ||
| } | ||
|
|
||
| // Default: put .refitter file in current directory | ||
| return ".refitter"; | ||
| } | ||
|
christianhelle marked this conversation as resolved.
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The File.WriteAllTextAsync and Directory.CreateDirectory operations lack error handling. If the file system operation fails (e.g., due to permissions, disk space, or path issues), the exception will propagate to the outer catch handler, which may provide a confusing error message since the main code generation has already completed successfully. Consider wrapping these operations in a try-catch block to provide a more specific error message about the settings file creation failure.