Skip to content

Commit 1657533

Browse files
author
mritd
committed
refactor(cmd): refactor cmd
refactor cmd Signed-off-by: mritd <[email protected]>
1 parent a16e938 commit 1657533

File tree

13 files changed

+194
-240
lines changed

13 files changed

+194
-240
lines changed

cmd/branch.go

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
package cmd
2+
3+
import (
4+
"github.com/mritd/gitflow-toolkit/consts"
5+
"github.com/mritd/gitflow-toolkit/git"
6+
"github.com/spf13/cobra"
7+
)
8+
9+
// Create feature branch
10+
func NewFeatBranch() *cobra.Command {
11+
return &cobra.Command{
12+
Use: "feat BRANCH_NAME",
13+
Short: "Create feature branch",
14+
Long: `
15+
Create a branch with a prefix of feat.`,
16+
Aliases: []string{"git-feat"},
17+
Run: func(cmd *cobra.Command, args []string) {
18+
if len(args) != 1 {
19+
_ = cmd.Help()
20+
} else {
21+
git.Checkout(consts.FEAT, args[0])
22+
}
23+
},
24+
}
25+
}
26+
27+
// Create fix branch
28+
func NewFixBranch() *cobra.Command {
29+
return &cobra.Command{
30+
Use: "fix BRANCH_NAME",
31+
Short: "Create fix branch",
32+
Long: `
33+
Create a branch with a prefix of fix.`,
34+
Aliases: []string{"git-fix"},
35+
Run: func(cmd *cobra.Command, args []string) {
36+
if len(args) != 1 {
37+
_ = cmd.Help()
38+
} else {
39+
git.Checkout(consts.FIX, args[0])
40+
}
41+
},
42+
}
43+
}
44+
45+
// Create hotfix branch
46+
func NewHotFixBranch() *cobra.Command {
47+
return &cobra.Command{
48+
Use: "hotfix BRANCH_NAME",
49+
Short: "Create hotfix branch",
50+
Long: `
51+
Create a branch with a prefix of hotfix.`,
52+
Aliases: []string{"git-hotfix"},
53+
Run: func(cmd *cobra.Command, args []string) {
54+
if len(args) != 1 {
55+
_ = cmd.Help()
56+
} else {
57+
git.Checkout(consts.HOTFIX, args[0])
58+
}
59+
},
60+
}
61+
}
62+
63+
// Create perf branch
64+
func NewPerfBranch() *cobra.Command {
65+
return &cobra.Command{
66+
Use: "perf BRANCH_NAME",
67+
Short: "Create perf branch",
68+
Long: `
69+
Create a branch with a prefix of perf.`,
70+
Aliases: []string{"git-perf"},
71+
Run: func(cmd *cobra.Command, args []string) {
72+
if len(args) != 1 {
73+
_ = cmd.Help()
74+
} else {
75+
git.Checkout(consts.PERF, args[0])
76+
}
77+
},
78+
}
79+
}
80+
81+
// Create refactor branch
82+
func NewRefactorBranch() *cobra.Command {
83+
return &cobra.Command{
84+
Use: "refactor BRANCH_NAME",
85+
Short: "Create refactor branch",
86+
Long: `
87+
Create a branch with a prefix of refactor.`,
88+
Aliases: []string{"git-refactor"},
89+
Run: func(cmd *cobra.Command, args []string) {
90+
if len(args) != 1 {
91+
_ = cmd.Help()
92+
} else {
93+
git.Checkout(consts.REFACTOR, args[0])
94+
}
95+
},
96+
}
97+
}
98+
99+
// Create test branch
100+
func NewTestBranch() *cobra.Command {
101+
return &cobra.Command{
102+
Use: "test BRANCH_NAME",
103+
Short: "Create test branch",
104+
Long: `
105+
Create a branch with a prefix of test.`,
106+
Aliases: []string{"git-test"},
107+
Run: func(cmd *cobra.Command, args []string) {
108+
if len(args) != 1 {
109+
_ = cmd.Help()
110+
} else {
111+
git.Checkout(consts.TEST, args[0])
112+
}
113+
},
114+
}
115+
}
116+
117+
// Create chore branch
118+
func NewChoreBranch() *cobra.Command {
119+
return &cobra.Command{
120+
Use: "chore BRANCH_NAME",
121+
Short: "Create chore branch",
122+
Long: `
123+
Create a branch with a prefix of chore.`,
124+
Aliases: []string{"git-chore"},
125+
Run: func(cmd *cobra.Command, args []string) {
126+
if len(args) != 1 {
127+
_ = cmd.Help()
128+
} else {
129+
git.Checkout(consts.CHORE, args[0])
130+
}
131+
132+
},
133+
}
134+
}
135+
136+
// Create style branch
137+
func NewStyleBranch() *cobra.Command {
138+
return &cobra.Command{
139+
Use: "style BRANCH_NAME",
140+
Short: "Create style branch",
141+
Long: `
142+
Create a branch with a prefix of style.`,
143+
Aliases: []string{"git-style"},
144+
Run: func(cmd *cobra.Command, args []string) {
145+
if len(args) != 1 {
146+
_ = cmd.Help()
147+
} else {
148+
git.Checkout(consts.STYLE, args[0])
149+
}
150+
},
151+
}
152+
}
153+
154+
// Create docs branch
155+
func NewDocsBranch() *cobra.Command {
156+
return &cobra.Command{
157+
Use: "docs BRANCH_NAME",
158+
Short: "Create docs branch",
159+
Long: `
160+
Create a branch with a prefix of docs.`,
161+
Aliases: []string{"git-docs"},
162+
Run: func(cmd *cobra.Command, args []string) {
163+
if len(args) != 1 {
164+
_ = cmd.Help()
165+
} else {
166+
git.Checkout(consts.DOCS, args[0])
167+
}
168+
},
169+
}
170+
}

cmd/chore.go

Lines changed: 0 additions & 25 deletions
This file was deleted.

cmd/docs.go

Lines changed: 0 additions & 24 deletions
This file was deleted.

cmd/feat.go

Lines changed: 0 additions & 24 deletions
This file was deleted.

cmd/fix.go

Lines changed: 0 additions & 24 deletions
This file was deleted.

cmd/hotfix.go

Lines changed: 0 additions & 24 deletions
This file was deleted.

cmd/perf.go

Lines changed: 0 additions & 24 deletions
This file was deleted.

cmd/ps.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ import (
55
"github.com/spf13/cobra"
66
)
77

8+
// Push local branch to remote git server
89
func NewPs() *cobra.Command {
910
return &cobra.Command{
1011
Use: "ps",
11-
Short: "Push local branch to remote",
12+
Short: "Push local branch to remote git server",
1213
Long: `
13-
Push local branch to remote.`,
14+
Push local branch to remote git server.`,
1415
Aliases: []string{"git-ps"},
1516
Run: func(cmd *cobra.Command, args []string) {
1617
git.Push()

cmd/refactor.go

Lines changed: 0 additions & 24 deletions
This file was deleted.

cmd/root.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,19 @@ func init() {
3030
// add sub cmd
3131
RootCmd.AddCommand(NewCi())
3232
RootCmd.AddCommand(NewCm())
33-
RootCmd.AddCommand(NewFeat())
34-
RootCmd.AddCommand(NewFix())
35-
RootCmd.AddCommand(NewDocs())
36-
RootCmd.AddCommand(NewStyle())
37-
RootCmd.AddCommand(NewRefactor())
38-
RootCmd.AddCommand(NewPerf())
39-
RootCmd.AddCommand(NewHotFix())
40-
RootCmd.AddCommand(NewTest())
41-
RootCmd.AddCommand(NewChore())
33+
RootCmd.AddCommand(NewFeatBranch())
34+
RootCmd.AddCommand(NewFixBranch())
35+
RootCmd.AddCommand(NewDocsBranch())
36+
RootCmd.AddCommand(NewStyleBranch())
37+
RootCmd.AddCommand(NewRefactorBranch())
38+
RootCmd.AddCommand(NewPerfBranch())
39+
RootCmd.AddCommand(NewHotFixBranch())
40+
RootCmd.AddCommand(NewTestBranch())
41+
RootCmd.AddCommand(NewChoreBranch())
4242
RootCmd.AddCommand(NewInstall())
4343
RootCmd.AddCommand(NewUninstall())
4444
RootCmd.AddCommand(NewPs())
45+
RootCmd.AddCommand(NewVersion())
4546
}
4647

4748
func initConfig() {

0 commit comments

Comments
 (0)