Skip to content

Commit 0e6ecff

Browse files
committed
simplify Convert func
1 parent 327ab44 commit 0e6ecff

File tree

3 files changed

+7
-17
lines changed

3 files changed

+7
-17
lines changed

internal/cli/adv2new/adv2new.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010

1111
func Builder() *cobra.Command {
1212
o := &cli.BaseOpts{
13-
Fs: afero.NewOsFs(),
14-
Converter: cli.ConvertFunc(convert.AdvancedClusterToNew),
13+
Fs: afero.NewOsFs(),
14+
Convert: convert.AdvancedClusterToNew,
1515
}
1616
cmd := &cobra.Command{
1717
Use: "advancedClusterToNew",

internal/cli/clu2adv/clu2adv.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ func Builder() *cobra.Command {
1717
Fs: afero.NewOsFs(),
1818
},
1919
}
20-
o.Converter = cli.ConvertFunc(func(config []byte) ([]byte, error) {
20+
o.Convert = func(config []byte) ([]byte, error) {
2121
return convert.ClusterToAdvancedCluster(config, o.includeMoved)
22-
})
22+
}
2323
cmd := &cobra.Command{
2424
Use: "clusterToAdvancedCluster",
2525
Short: "Convert cluster to advanced_cluster preview provider 2.0.0",

internal/cli/common.go

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,12 @@ import (
99
"github.com/spf13/afero"
1010
)
1111

12-
// Converter defines the interface for different conversion functions.
13-
type Converter interface {
14-
Convert(config []byte) ([]byte, error)
15-
}
16-
17-
// ConvertFunc is a function type that implements the Converter interface.
18-
type ConvertFunc func(config []byte) ([]byte, error)
19-
20-
func (f ConvertFunc) Convert(config []byte) ([]byte, error) {
21-
return f(config)
22-
}
12+
type ConvertFn func(config []byte) ([]byte, error)
2313

2414
// BaseOpts contains common functionality for CLI commands that convert files.
2515
type BaseOpts struct {
2616
Fs afero.Fs
27-
Converter Converter
17+
Convert ConvertFn
2818
File string
2919
Output string
3020
ReplaceOutput bool
@@ -60,7 +50,7 @@ func (o *BaseOpts) generateFile(allowParseErrors bool) error {
6050
return fmt.Errorf("failed to read file %s: %w", o.File, err)
6151
}
6252

63-
outConfig, err := o.Converter.Convert(inConfig)
53+
outConfig, err := o.Convert(inConfig)
6454
if err != nil {
6555
if allowParseErrors {
6656
outConfig = []byte("# CONVERT ERROR: " + err.Error() + "\n\n")

0 commit comments

Comments
 (0)