|
| 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 | +} |
0 commit comments