Skip to content

Commit

Permalink
cleanup/refactory : Re-Generate Alpha Command
Browse files Browse the repository at this point in the history
refactor: improve error handling, encapsulate logic, and streamline flow in rescaffold command

- Improved error handling by wrapping errors with `fmt.Errorf` and propagating them instead of using `log.Fatalf`. This ensures better debugging and more graceful error recovery.
- Encapsulated repeated logic such as directory changes, config loading, and path handling into dedicated helper functions, reducing redundancy and improving code readability.
- Ensured consistent logging: logging is reserved for informative messages like plugin migration steps, while error handling uses `fmt.Errorf` for consistency.
- Simplified control flow by removing redundant error checks and unnecessary logic, making the code easier to follow without altering functionality.
- Renamed methods to improve clarity and follow established naming conventions.
- Avoided unnecessary exports by keeping methods private where applicable.
- Ensured the refactored code is properly encapsulated under the command structure (`rescaffold`) as part of the appropriate command directory structure.
  • Loading branch information
camilamacedo86 committed Sep 22, 2024
1 parent 471ce46 commit 168a6c9
Show file tree
Hide file tree
Showing 2 changed files with 158 additions and 126 deletions.
9 changes: 5 additions & 4 deletions pkg/cli/alpha/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ import (
log "github.com/sirupsen/logrus"

"github.com/spf13/cobra"
"sigs.k8s.io/kubebuilder/v4/pkg/rescaffold"

"sigs.k8s.io/kubebuilder/v4/pkg/command/generate"
)

// NewScaffoldCommand return a new scaffold command
func NewScaffoldCommand() *cobra.Command {
opts := rescaffold.MigrateOptions{}
opts := generate.Generate{}
scaffoldCmd := &cobra.Command{
Use: "generate",
Short: "Re-scaffold an existing Kuberbuilder project",
Expand All @@ -36,8 +37,8 @@ Then we will re-scaffold the project by Kubebuilder in the directory specified b
return opts.Validate()
},
Run: func(_ *cobra.Command, _ []string) {
if err := opts.Rescaffold(); err != nil {
log.Fatalf("Failed to rescaffold %s", err)
if err := opts.Generate(); err != nil {
log.Fatalf("Failed to command %s", err)
}
},
}
Expand Down
Loading

0 comments on commit 168a6c9

Please sign in to comment.