Skip to content

Commit cf4df8c

Browse files
author
mritd
committed
refactor(cmd): refactor cmd code
refactor cmd code Signed-off-by: mritd <[email protected]>
1 parent 567f0ed commit cf4df8c

32 files changed

+186
-830
lines changed

Makefile

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
1-
BUILD_VERSION := $(version)
2-
BUILD_TIME := $(shell date "+%F %T")
1+
BUILD_VERSION := $(shell cat version)
2+
BUILD_DATE := $(shell date "+%F %T")
33
COMMIT_SHA1 := $(shell git rev-parse HEAD)
44

55
all:
66
gox -osarch="darwin/amd64 linux/386 linux/amd64" \
77
-output="dist/{{.Dir}}_{{.OS}}_{{.Arch}}" \
88
-ldflags "-X 'github.com/mritd/gitflow-toolkit/cmd.Version=${BUILD_VERSION}' \
99
-X 'github.com/mritd/gitflow-toolkit/cmd.BuildTime=${BUILD_TIME}' \
10-
-X 'github.com/mritd/gitflow-toolkit/cmd.CommitID=${COMMIT_SHA1}'"
10+
-X 'github.com/mritd/gitflow-toolkit/cmd.CommitID=${COMMIT_SHA1}' \
11+
-w -s"
1112

1213
release: all
13-
ghr -u mritd -t $(GITHUB_RELEASE_TOKEN) -replace -recreate --debug $(version) dist
14+
ghr -u mritd -t ${GITHUB_RELEASE_TOKEN} -replace -recreate --debug ${BUILD_VERSION} dist
1415

1516
clean:
1617
rm -rf dist
1718

1819
install:
1920
go install -ldflags "-X 'github.com/mritd/gitflow-toolkit/cmd.Version=${BUILD_VERSION}' \
2021
-X 'github.com/mritd/gitflow-toolkit/cmd.BuildTime=${BUILD_TIME}' \
21-
-X 'github.com/mritd/gitflow-toolkit/cmd.CommitID=${COMMIT_SHA1}'"
22+
-X 'github.com/mritd/gitflow-toolkit/cmd.CommitID=${COMMIT_SHA1}' \
23+
-w -s"
2224

2325
.PHONY : all release clean install
2426

cmd/chore.go

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,25 @@
1-
// Copyright © 2018 mritd <[email protected]>
2-
//
3-
// Permission is hereby granted, free of charge, to any person obtaining a copy
4-
// of this software and associated documentation files (the "Software"), to deal
5-
// in the Software without restriction, including without limitation the rights
6-
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7-
// copies of the Software, and to permit persons to whom the Software is
8-
// furnished to do so, subject to the following conditions:
9-
//
10-
// The above copyright notice and this permission notice shall be included in
11-
// all copies or substantial portions of the Software.
12-
//
13-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14-
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15-
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16-
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17-
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19-
// THE SOFTWARE.
20-
211
package cmd
222

233
import (
24-
"fmt"
25-
"os"
26-
27-
"github.com/mritd/gitflow-toolkit/pkg/consts"
28-
"github.com/mritd/gitflow-toolkit/pkg/util"
4+
"github.com/mritd/gitflow-toolkit/consts"
5+
"github.com/mritd/gitflow-toolkit/util"
296
"github.com/spf13/cobra"
307
)
318

329
func NewChore() *cobra.Command {
3310
return &cobra.Command{
34-
Use: "chore",
35-
Short: "创建 chore 分支",
11+
Use: "chore BRANCH_NAME",
12+
Short: "Create chore branch",
3613
Long: `
37-
创建一个以 chore 开头的分支`,
14+
Create a branch with a prefix of chore.`,
3815
Aliases: []string{"git-chore"},
3916
Run: func(cmd *cobra.Command, args []string) {
4017
if len(args) != 1 {
41-
fmt.Println("branch name is blank")
42-
os.Exit(1)
18+
_ = cmd.Help()
19+
} else {
20+
util.Checkout(consts.CHORE, args[0])
4321
}
44-
util.Checkout(consts.CHORE, args[0])
22+
4523
},
4624
}
4725
}

cmd/ci.go

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,12 @@
1-
// Copyright © 2018 mritd <[email protected]>
2-
//
3-
// Permission is hereby granted, free of charge, to any person obtaining a copy
4-
// of this software and associated documentation files (the "Software"), to deal
5-
// in the Software without restriction, including without limitation the rights
6-
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7-
// copies of the Software, and to permit persons to whom the Software is
8-
// furnished to do so, subject to the following conditions:
9-
//
10-
// The above copyright notice and this permission notice shall be included in
11-
// all copies or substantial portions of the Software.
12-
//
13-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14-
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15-
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16-
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17-
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19-
// THE SOFTWARE.
20-
211
package cmd
222

233
import (
244
"fmt"
255
"os"
266

27-
"github.com/mritd/gitflow-toolkit/pkg/commit"
28-
"github.com/mritd/gitflow-toolkit/pkg/consts"
29-
"github.com/mritd/gitflow-toolkit/pkg/util"
7+
"github.com/mritd/gitflow-toolkit/commit"
8+
"github.com/mritd/gitflow-toolkit/consts"
9+
"github.com/mritd/gitflow-toolkit/util"
3010
"github.com/spf13/cobra"
3111
)
3212

cmd/cm.go

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,23 @@
1-
// Copyright © 2018 mritd <[email protected]>
2-
//
3-
// Permission is hereby granted, free of charge, to any person obtaining a copy
4-
// of this software and associated documentation files (the "Software"), to deal
5-
// in the Software without restriction, including without limitation the rights
6-
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7-
// copies of the Software, and to permit persons to whom the Software is
8-
// furnished to do so, subject to the following conditions:
9-
//
10-
// The above copyright notice and this permission notice shall be included in
11-
// all copies or substantial portions of the Software.
12-
//
13-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14-
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15-
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16-
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17-
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19-
// THE SOFTWARE.
20-
211
package cmd
222

233
import (
24-
"github.com/mritd/gitflow-toolkit/pkg/commit"
4+
"github.com/mritd/gitflow-toolkit/commit"
255
"github.com/spf13/cobra"
266
)
277

288
func NewCm() *cobra.Command {
299
return &cobra.Command{
30-
Use: "cm",
31-
Short: "检查文件内容是否符合 Angular 社区规范",
10+
Use: "cm FILE",
11+
Short: "Check the commit message specification",
3212
Long: `
33-
该命令接受一个 git commit message 的文件路径,并检查其格式是否符合 Angular 社区规范`,
13+
Check if the file content meets the Angular Community Specification.`,
3414
Aliases: []string{"git-cm", "commit-msg"},
3515
Run: func(cmd *cobra.Command, args []string) {
36-
commit.CheckCommitMessage(args)
16+
if len(args) != 1 {
17+
_ = cmd.Help()
18+
} else {
19+
commit.CheckCommitMessage(args)
20+
}
3721
},
3822
}
3923
}

cmd/docs.go

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,24 @@
1-
// Copyright © 2018 mritd <[email protected]>
2-
//
3-
// Permission is hereby granted, free of charge, to any person obtaining a copy
4-
// of this software and associated documentation files (the "Software"), to deal
5-
// in the Software without restriction, including without limitation the rights
6-
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7-
// copies of the Software, and to permit persons to whom the Software is
8-
// furnished to do so, subject to the following conditions:
9-
//
10-
// The above copyright notice and this permission notice shall be included in
11-
// all copies or substantial portions of the Software.
12-
//
13-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14-
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15-
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16-
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17-
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19-
// THE SOFTWARE.
20-
211
package cmd
222

233
import (
24-
"fmt"
25-
"os"
26-
27-
"github.com/mritd/gitflow-toolkit/pkg/consts"
28-
"github.com/mritd/gitflow-toolkit/pkg/util"
4+
"github.com/mritd/gitflow-toolkit/consts"
5+
"github.com/mritd/gitflow-toolkit/util"
296
"github.com/spf13/cobra"
307
)
318

329
func NewDocs() *cobra.Command {
3310
return &cobra.Command{
34-
Use: "docs",
35-
Short: "创建 docs 分支",
11+
Use: "docs BRANCH_NAME",
12+
Short: "Create docs branch",
3613
Long: `
37-
创建一个以 docs 开头的分支`,
14+
Create a branch with a prefix of docs.`,
3815
Aliases: []string{"git-docs"},
3916
Run: func(cmd *cobra.Command, args []string) {
4017
if len(args) != 1 {
41-
fmt.Println("branch name is blank")
42-
os.Exit(1)
18+
_ = cmd.Help()
19+
} else {
20+
util.Checkout(consts.DOCS, args[0])
4321
}
44-
util.Checkout(consts.DOCS, args[0])
4522
},
4623
}
4724
}

cmd/feat.go

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,24 @@
1-
// Copyright © 2018 mritd <[email protected]>
2-
//
3-
// Permission is hereby granted, free of charge, to any person obtaining a copy
4-
// of this software and associated documentation files (the "Software"), to deal
5-
// in the Software without restriction, including without limitation the rights
6-
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7-
// copies of the Software, and to permit persons to whom the Software is
8-
// furnished to do so, subject to the following conditions:
9-
//
10-
// The above copyright notice and this permission notice shall be included in
11-
// all copies or substantial portions of the Software.
12-
//
13-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14-
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15-
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16-
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17-
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19-
// THE SOFTWARE.
20-
211
package cmd
222

233
import (
24-
"fmt"
25-
"os"
26-
27-
"github.com/mritd/gitflow-toolkit/pkg/consts"
28-
"github.com/mritd/gitflow-toolkit/pkg/util"
4+
"github.com/mritd/gitflow-toolkit/consts"
5+
"github.com/mritd/gitflow-toolkit/util"
296
"github.com/spf13/cobra"
307
)
318

329
func NewFeat() *cobra.Command {
3310
return &cobra.Command{
34-
Use: "feat",
35-
Short: "创建 feat 分支",
11+
Use: "feat BRANCH_NAME",
12+
Short: "Create feature branch",
3613
Long: `
37-
创建一个以 feat 开头的分支`,
14+
Create a branch with a prefix of feat.`,
3815
Aliases: []string{"git-feat"},
3916
Run: func(cmd *cobra.Command, args []string) {
4017
if len(args) != 1 {
41-
fmt.Println("branch name is blank")
42-
os.Exit(1)
18+
_ = cmd.Help()
19+
} else {
20+
util.Checkout(consts.FEAT, args[0])
4321
}
44-
util.Checkout(consts.FEAT, args[0])
4522
},
4623
}
4724
}

cmd/fix.go

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,24 @@
1-
// Copyright © 2018 mritd <[email protected]>
2-
//
3-
// Permission is hereby granted, free of charge, to any person obtaining a copy
4-
// of this software and associated documentation files (the "Software"), to deal
5-
// in the Software without restriction, including without limitation the rights
6-
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7-
// copies of the Software, and to permit persons to whom the Software is
8-
// furnished to do so, subject to the following conditions:
9-
//
10-
// The above copyright notice and this permission notice shall be included in
11-
// all copies or substantial portions of the Software.
12-
//
13-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14-
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15-
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16-
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17-
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19-
// THE SOFTWARE.
20-
211
package cmd
222

233
import (
24-
"fmt"
25-
"os"
26-
27-
"github.com/mritd/gitflow-toolkit/pkg/consts"
28-
"github.com/mritd/gitflow-toolkit/pkg/util"
4+
"github.com/mritd/gitflow-toolkit/consts"
5+
"github.com/mritd/gitflow-toolkit/util"
296
"github.com/spf13/cobra"
307
)
318

329
func NewFix() *cobra.Command {
3310
return &cobra.Command{
34-
Use: "fix",
35-
Short: "创建 fix 分支",
11+
Use: "fix BRANCH_NAME",
12+
Short: "Create fix branch",
3613
Long: `
37-
创建一个以 fix 开头的分支`,
14+
Create a branch with a prefix of fix.`,
3815
Aliases: []string{"git-fix"},
3916
Run: func(cmd *cobra.Command, args []string) {
4017
if len(args) != 1 {
41-
fmt.Println("branch name is blank")
42-
os.Exit(1)
18+
_ = cmd.Help()
19+
} else {
20+
util.Checkout(consts.FIX, args[0])
4321
}
44-
util.Checkout(consts.FIX, args[0])
4522
},
4623
}
4724
}

cmd/hotfix.go

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,24 @@
1-
// Copyright © 2018 mritd <[email protected]>
2-
//
3-
// Permission is hereby granted, free of charge, to any person obtaining a copy
4-
// of this software and associated documentation files (the "Software"), to deal
5-
// in the Software without restriction, including without limitation the rights
6-
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7-
// copies of the Software, and to permit persons to whom the Software is
8-
// furnished to do so, subject to the following conditions:
9-
//
10-
// The above copyright notice and this permission notice shall be included in
11-
// all copies or substantial portions of the Software.
12-
//
13-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14-
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15-
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16-
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17-
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19-
// THE SOFTWARE.
20-
211
package cmd
222

233
import (
24-
"fmt"
25-
"os"
26-
27-
"github.com/mritd/gitflow-toolkit/pkg/consts"
28-
"github.com/mritd/gitflow-toolkit/pkg/util"
4+
"github.com/mritd/gitflow-toolkit/consts"
5+
"github.com/mritd/gitflow-toolkit/util"
296
"github.com/spf13/cobra"
307
)
318

329
func NewHotFix() *cobra.Command {
3310
return &cobra.Command{
34-
Use: "hotfix",
35-
Short: "创建 hotfix 分支",
11+
Use: "hotfix BRANCH_NAME",
12+
Short: "Create hotfix branch",
3613
Long: `
37-
创建一个以 hotfix 开头的分支,通常用于对 master 的紧急修复`,
14+
Create a branch with a prefix of hotfix.`,
3815
Aliases: []string{"git-hotfix"},
3916
Run: func(cmd *cobra.Command, args []string) {
4017
if len(args) != 1 {
41-
fmt.Println("branch name is blank")
42-
os.Exit(1)
18+
_ = cmd.Help()
19+
} else {
20+
util.Checkout(consts.HOTFIX, args[0])
4321
}
44-
util.Checkout(consts.HOTFIX, args[0])
4522
},
4623
}
4724
}

0 commit comments

Comments
 (0)