Skip to content

Commit d9c3878

Browse files
author
Tobias Meinhardt
committed
Rewrite feature command
1 parent eed4fb0 commit d9c3878

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

pkg/cli/cmd/feature.go

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,40 @@ package cmd
33
import (
44
"github.com/meinto/glow"
55

6+
"github.com/meinto/glow/pkg/cli/cmd/internal/command"
67
"github.com/meinto/glow/pkg/cli/cmd/internal/util"
78
"github.com/spf13/cobra"
89
"github.com/spf13/viper"
910
)
1011

11-
func init() {
12-
RootCmd.Cmd().AddCommand(featureCmd)
12+
type FeatureCommand struct {
13+
command.Service
1314
}
1415

15-
var featureCmd = &cobra.Command{
16-
Use: "feature",
17-
Short: "create a feature branch",
18-
Args: cobra.MinimumNArgs(1),
19-
Run: func(cmd *cobra.Command, args []string) {
20-
featureName := args[0]
16+
func (cmd *FeatureCommand) PostSetup(parent command.Service) command.Service {
17+
parent.Add(cmd)
18+
return cmd
19+
}
20+
21+
var featureCmd = SetupFeatureCommand(RootCmd)
22+
23+
func SetupFeatureCommand(parent command.Service) command.Service {
24+
return command.Setup(&FeatureCommand{
25+
&command.Command{
26+
Command: &cobra.Command{
27+
Use: "feature",
28+
Short: "create a feature branch",
29+
Args: cobra.MinimumNArgs(1),
30+
},
31+
Run: func(cmd command.Service, args []string) {
32+
featureName := args[0]
2133

22-
feature, err := glow.NewFeature(viper.GetString("author"), featureName)
23-
util.ExitOnError(err)
34+
feature, err := glow.NewFeature(viper.GetString("author"), featureName)
35+
util.ExitOnError(err)
2436

25-
g, err := util.GetGitClient()
26-
util.ExitOnError(g.Create(feature, rootCmdOptions.SkipChecks))
27-
util.ExitOnError(g.Checkout(feature))
28-
},
37+
util.ExitOnError(cmd.GitClient().Create(feature, rootCmdOptions.SkipChecks))
38+
util.ExitOnError(cmd.GitClient().Checkout(feature))
39+
},
40+
},
41+
})
2942
}

0 commit comments

Comments
 (0)