Skip to content

Commit 168a6c9

Browse files
cleanup/refactory : Re-Generate Alpha Command
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.
1 parent 471ce46 commit 168a6c9

File tree

2 files changed

+158
-126
lines changed

2 files changed

+158
-126
lines changed

pkg/cli/alpha/generate.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@ import (
1717
log "github.com/sirupsen/logrus"
1818

1919
"github.com/spf13/cobra"
20-
"sigs.k8s.io/kubebuilder/v4/pkg/rescaffold"
20+
21+
"sigs.k8s.io/kubebuilder/v4/pkg/command/generate"
2122
)
2223

2324
// NewScaffoldCommand return a new scaffold command
2425
func NewScaffoldCommand() *cobra.Command {
25-
opts := rescaffold.MigrateOptions{}
26+
opts := generate.Generate{}
2627
scaffoldCmd := &cobra.Command{
2728
Use: "generate",
2829
Short: "Re-scaffold an existing Kuberbuilder project",
@@ -36,8 +37,8 @@ Then we will re-scaffold the project by Kubebuilder in the directory specified b
3637
return opts.Validate()
3738
},
3839
Run: func(_ *cobra.Command, _ []string) {
39-
if err := opts.Rescaffold(); err != nil {
40-
log.Fatalf("Failed to rescaffold %s", err)
40+
if err := opts.Generate(); err != nil {
41+
log.Fatalf("Failed to command %s", err)
4142
}
4243
},
4344
}

0 commit comments

Comments
 (0)