Skip to content

Commit cd214e8

Browse files
committed
refactor RunE
1 parent 49a1bf3 commit cd214e8

File tree

3 files changed

+14
-16
lines changed

3 files changed

+14
-16
lines changed

internal/cli/adv2new/adv2new.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,7 @@ func Builder() *cobra.Command {
1818
Long: "Convert a Terraform configuration from mongodbatlas_advanced_cluster in provider version 1.X.X (SDKv2)" +
1919
" to version 2.X.X (TPF - Terraform Plugin Framework)",
2020
Aliases: []string{"adv2new"},
21-
RunE: func(_ *cobra.Command, _ []string) error {
22-
if err := o.PreRun(); err != nil {
23-
return err
24-
}
25-
return o.Run()
26-
},
21+
RunE: o.RunE,
2722
}
2823
cli.SetupCommonFlags(cmd, o)
2924
return cmd

internal/cli/clu2adv/clu2adv.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,7 @@ func Builder() *cobra.Command {
2626
Long: "Convert a Terraform configuration from mongodbatlas_cluster to " +
2727
"mongodbatlas_advanced_cluster preview provider 2.0.0",
2828
Aliases: []string{"clu2adv"},
29-
RunE: func(_ *cobra.Command, _ []string) error {
30-
if err := o.PreRun(); err != nil {
31-
return err
32-
}
33-
return o.Run()
34-
},
29+
RunE: o.RunE,
3530
}
3631
cli.SetupCommonFlags(cmd, o.BaseOpts)
3732
cmd.Flags().BoolVarP(&o.includeMoved, flag.IncludeMoved, flag.IncludeMovedShort, false,

internal/cli/common.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,16 @@ type BaseOpts struct {
2323
Watch bool
2424
}
2525

26-
// PreRun validates the input and output files before running the command.
27-
func (o *BaseOpts) PreRun() error {
26+
// RunE is the entry point for the command.
27+
func (o *BaseOpts) RunE(cmd *cobra.Command, args []string) error {
28+
if err := o.preRun(); err != nil {
29+
return err
30+
}
31+
return o.run()
32+
}
33+
34+
// preRun validates the input and output files before running the command.
35+
func (o *BaseOpts) preRun() error {
2836
if err := file.MustExist(o.Fs, o.File); err != nil {
2937
return err
3038
}
@@ -34,8 +42,8 @@ func (o *BaseOpts) PreRun() error {
3442
return nil
3543
}
3644

37-
// Run executes the conversion and optionally watches for file changes.
38-
func (o *BaseOpts) Run() error {
45+
// run executes the conversion and optionally watches for file changes.
46+
func (o *BaseOpts) run() error {
3947
if err := o.generateFile(false); err != nil {
4048
return err
4149
}

0 commit comments

Comments
 (0)