Run executes the code generator with the given options
(opts *GeneratorOptions)
| 43 | |
| 44 | // Run executes the code generator with the given options |
| 45 | func Run(opts *GeneratorOptions) error { |
| 46 | // If force flag is set, clean up existing files first |
| 47 | if opts.Force { |
| 48 | logger.Printf("Force flag detected, cleaning up existing generated files...") |
| 49 | if cleanupErr := cleanupGeneratedFiles(opts); cleanupErr != nil { |
| 50 | logger.Printf("Warning: Failed to cleanup generated files: %v", cleanupErr) |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | err := run(opts) |
| 55 | |
| 56 | // Check if the error is due to compile-time guard conflicts |
| 57 | if err != nil && isCompileGuardError(err.Error()) { |
| 58 | logger.Printf("Detected compile-time guard conflict. Attempting to regenerate...") |
| 59 | |
| 60 | // Try to clean up and regenerate |
| 61 | if cleanupErr := cleanupGeneratedFiles(opts); cleanupErr != nil { |
| 62 | logger.Printf("Warning: Failed to cleanup generated files: %v", cleanupErr) |
| 63 | } |
| 64 | |
| 65 | // Retry generation |
| 66 | logger.Printf("Retrying code generation...") |
| 67 | return run(opts) |
| 68 | } |
| 69 | |
| 70 | return err |
| 71 | } |
| 72 | |
| 73 | func run(opts *GeneratorOptions) error { |
| 74 | // Determine mode: file-based or package-based |
nothing calls this directly
no test coverage detected