Skip to content

Commit b2a1939

Browse files
committed
refactor(all): update dep, refactor code
update dep, refactor code Signed-off-by: mritd <[email protected]>
1 parent 84684de commit b2a1939

File tree

10 files changed

+125
-111
lines changed

10 files changed

+125
-111
lines changed

Makefile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
BUILD_VERSION := $(shell cat version)
2-
BUILD_DATE := $(shell date "+%F %T")
2+
BUILD_TIME := $(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}' \
11-
-w -s"
10+
-X 'github.com/mritd/gitflow-toolkit/cmd.CommitID=${COMMIT_SHA1}'"
1211

1312
release: all
1413
ghr -u mritd -t ${GITHUB_RELEASE_TOKEN} -replace -recreate --debug ${BUILD_VERSION} dist
@@ -19,11 +18,12 @@ clean:
1918
install:
2019
go install -ldflags "-X 'github.com/mritd/gitflow-toolkit/cmd.Version=${BUILD_VERSION}' \
2120
-X 'github.com/mritd/gitflow-toolkit/cmd.BuildTime=${BUILD_TIME}' \
22-
-X 'github.com/mritd/gitflow-toolkit/cmd.CommitID=${COMMIT_SHA1}' \
23-
-w -s"
21+
-X 'github.com/mritd/gitflow-toolkit/cmd.CommitID=${COMMIT_SHA1}'"
2422

2523
.PHONY : all release clean install
2624

2725
.EXPORT_ALL_VARIABLES:
2826

29-
GO111MODULE = on
27+
GO111MODULE = on
28+
GOPROXY = https://goproxy.io
29+
GOSUMDB = sum.golang.google.cn

cmd/install.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"github.com/spf13/cobra"
66
)
77

8+
var installDir string
9+
810
func NewInstall() *cobra.Command {
911
return &cobra.Command{
1012
Use: "install",
@@ -13,7 +15,7 @@ func NewInstall() *cobra.Command {
1315
Install gitflow-toolkit(only support *Unix).`,
1416
Aliases: []string{"install"},
1517
Run: func(cmd *cobra.Command, args []string) {
16-
utils.Install()
18+
utils.Install(installDir)
1719
},
1820
}
1921
}

cmd/root.go

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
package cmd
22

33
import (
4-
"github.com/mitchellh/go-homedir"
5-
"github.com/mritd/gitflow-toolkit/utils"
64
"github.com/spf13/cobra"
7-
"github.com/spf13/viper"
85
)
96

107
var cfgFile string
@@ -21,11 +18,14 @@ var RootCmd = &cobra.Command{
2118

2219
func init() {
2320

24-
// init config
25-
cobra.OnInitialize(initConfig)
21+
installCmd := NewInstall()
22+
installCmd.PersistentFlags().StringVar(&installDir, "dir", "/usr/local/bin", "install dir")
2623

27-
// add flags
28-
RootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.gitflow-toolkit.yaml)")
24+
uninstallCmd := NewUninstall()
25+
uninstallCmd.PersistentFlags().StringVar(&installDir, "dir", "/usr/local/bin", "install dir")
26+
27+
RootCmd.AddCommand(installCmd)
28+
RootCmd.AddCommand(uninstallCmd)
2929

3030
// add sub cmd
3131
RootCmd.AddCommand(NewCi())
@@ -39,21 +39,6 @@ func init() {
3939
RootCmd.AddCommand(NewHotFixBranch())
4040
RootCmd.AddCommand(NewTestBranch())
4141
RootCmd.AddCommand(NewChoreBranch())
42-
RootCmd.AddCommand(NewInstall())
43-
RootCmd.AddCommand(NewUninstall())
4442
RootCmd.AddCommand(NewPs())
4543
RootCmd.AddCommand(NewVersion())
4644
}
47-
48-
func initConfig() {
49-
if cfgFile != "" {
50-
viper.SetConfigFile(cfgFile)
51-
} else {
52-
home, err := homedir.Dir()
53-
utils.CheckAndExit(err)
54-
viper.AddConfigPath(home)
55-
viper.SetConfigName(".gitflow-toolkit")
56-
}
57-
viper.AutomaticEnv()
58-
viper.ReadInConfig()
59-
}

cmd/uninstall.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func NewUninstall() *cobra.Command {
1313
Uninstall gitflow-toolkit`,
1414
Aliases: []string{"uninstall"},
1515
Run: func(cmd *cobra.Command, args []string) {
16-
utils.Uninstall()
16+
utils.Uninstall(installDir)
1717
},
1818
}
1919
}

go.mod

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
module github.com/mritd/gitflow-toolkit
22

3+
go 1.13
4+
35
require (
4-
github.com/BurntSushi/toml v0.3.1 // indirect
5-
github.com/inconshreveable/mousetrap v1.0.0 // indirect
66
github.com/mitchellh/go-homedir v1.1.0
7-
github.com/mritd/promptx v0.0.0-20181104120837-d3bd32bd6d64
7+
github.com/mritd/promptx v0.0.0-20190919142911-51b6aa75496f
88
github.com/pkg/errors v0.8.1
9-
github.com/spf13/cobra v0.0.3
10-
github.com/spf13/viper v1.3.1
9+
github.com/spf13/cobra v0.0.5
1110
)

go.sum

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMn
88
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
99
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
1010
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
11+
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
12+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1113
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
1214
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1315
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
@@ -18,45 +20,47 @@ github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NH
1820
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
1921
github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDePerRcY=
2022
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
21-
github.com/mattn/go-runewidth v0.0.3 h1:a+kO+98RDGEfo6asOGMmpodZq4FNtnGP54yps8BzLR4=
22-
github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
23+
github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y=
24+
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
2325
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
2426
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
2527
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
2628
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
27-
github.com/mritd/promptx v0.0.0-20181104120837-d3bd32bd6d64 h1:XK7D4Ke4TnL3Ruf8XORFxHI5P5RkCGk1zSscunDcCdA=
28-
github.com/mritd/promptx v0.0.0-20181104120837-d3bd32bd6d64/go.mod h1:icKW5kjHMpPxfsbQy6hCd1FLhZFsztmnna3VJLQOC1M=
29-
github.com/mritd/readline v0.0.0-20180425151209-ae245b60ddeb h1:fB2rncglOnfNm4xZ/y5N00z1T9oFVLyadZVAPcVvyWQ=
30-
github.com/mritd/readline v0.0.0-20180425151209-ae245b60ddeb/go.mod h1:wvYAHAQUSCpYdQJIF/KWesOEv2JORGDkhM2hZzg+IOU=
29+
github.com/mritd/promptx v0.0.0-20190919142911-51b6aa75496f h1:g3nT0qYmKdzFCbupXN4/RJ5WbrI3UhGd8HWCIdgds3U=
30+
github.com/mritd/promptx v0.0.0-20190919142911-51b6aa75496f/go.mod h1:i1OtwqcaJpQ/FzJR0UcdYy0YLOGt4xgcAO+GTJ5MCE4=
31+
github.com/mritd/readline v0.0.0-20190430155141-1af16399dc52 h1:LtfLwyq20tlA4EZ/rF2JKG/ccNBZzfwOJZ72uPTqhlQ=
32+
github.com/mritd/readline v0.0.0-20190430155141-1af16399dc52/go.mod h1:9er/6+nnOsC7xIZIbVOZ40teP1ph7ei4OY6xLzuktOY=
33+
github.com/nbutton23/zxcvbn-go v0.0.0-20180912185939-ae427f1e4c1d/go.mod h1:o96djdrsSGy3AWPyBgZMAGfxZNfgntdJG+11KU4QvbU=
3134
github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc=
3235
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
3336
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
3437
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
3538
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
3639
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
40+
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
3741
github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI=
3842
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
3943
github.com/spf13/cast v1.3.0 h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8=
4044
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
41-
github.com/spf13/cobra v0.0.3 h1:ZlrZ4XsMRm04Fr5pSFxBgfND2EBVa1nLpiy1stUsX/8=
42-
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
45+
github.com/spf13/cobra v0.0.5 h1:f0B+LkLX6DtmRH1isoNA9VTtNUK9K8xYd28JNNfOv/s=
46+
github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU=
4347
github.com/spf13/jwalterweatherman v1.0.0 h1:XHEdyB+EcvlqZamSM4ZOMGlc93t6AcsBEu9Gc1vn7yk=
4448
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
4549
github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
4650
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
47-
github.com/spf13/viper v1.3.1 h1:5+8j8FTpnFV4nEImW/ofkzEt8VoOiLXxdYIDsB73T38=
48-
github.com/spf13/viper v1.3.1/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s=
49-
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
51+
github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s=
52+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
5053
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
54+
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
55+
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
5156
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
5257
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
5358
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
54-
golang.org/x/sys v0.0.0-20181031143558-9b800f95dbbc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
55-
golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a h1:1n5lsVfiQW3yfsRGu98756EH1YthsFqr/5mxHduZW2A=
5659
golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
60+
golang.org/x/sys v0.0.0-20190405154228-4b34438f7a67 h1:1Fzlr8kkDLQwqMP8GxrhptBLqZG/EDpiATneiZHY998=
61+
golang.org/x/sys v0.0.0-20190405154228-4b34438f7a67/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
5762
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
5863
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
59-
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
6064
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
6165
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
6266
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

utils/common.go

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ import (
1414
"github.com/mitchellh/go-homedir"
1515
)
1616

17-
const InstallBaseDir = "/usr/local/bin"
18-
1917
var GitFlowToolKitHome string
2018
var InstallPath string
2119
var HooksPath string
@@ -38,25 +36,6 @@ func init() {
3836
CheckAndExit(err)
3937
}
4038

41-
func BinPaths() []string {
42-
return []string{
43-
GitCMHookPath,
44-
InstallBaseDir + "/git-ci",
45-
InstallBaseDir + "/git-feat",
46-
InstallBaseDir + "/git-fix",
47-
InstallBaseDir + "/git-docs",
48-
InstallBaseDir + "/git-style",
49-
InstallBaseDir + "/git-refactor",
50-
InstallBaseDir + "/git-test",
51-
InstallBaseDir + "/git-chore",
52-
InstallBaseDir + "/git-perf",
53-
InstallBaseDir + "/git-hotfix",
54-
InstallBaseDir + "/git-xmr",
55-
InstallBaseDir + "/git-xpr",
56-
InstallBaseDir + "/git-ps",
57-
}
58-
}
59-
6039
func CheckErr(err error) bool {
6140
if err != nil {
6241
fmt.Println(err)
@@ -102,14 +81,10 @@ func TryExec(name string, arg ...string) error {
10281
return cmd.Run()
10382
}
10483

105-
func CheckRoot() {
84+
func Root() bool {
10685
u, err := user.Current()
10786
CheckAndExit(err)
108-
109-
if u.Uid != "0" || u.Gid != "0" {
110-
fmt.Println("This command must be run as root! (sudo)")
111-
os.Exit(1)
112-
}
87+
return u.Uid == "0" || u.Gid == "0"
11388
}
11489

11590
func OSEditInput() string {

utils/install.go

Lines changed: 49 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,58 @@ import (
44
"fmt"
55
"io"
66
"os"
7+
"os/exec"
8+
"path/filepath"
79
)
810

9-
func Install() {
11+
func Install(dir string) {
1012

11-
Uninstall()
12-
13-
fmt.Println("Install gitflow-toolkit")
14-
fmt.Println("Create install home dir")
15-
CheckAndExit(os.MkdirAll(GitFlowToolKitHome, 0755))
16-
17-
fmt.Println("Copy file to install home")
18-
currentFile, err := os.Open(CurrentPath)
19-
CheckAndExit(err)
20-
defer func() { _ = currentFile.Close() }()
21-
22-
installFile, err := os.OpenFile(InstallPath, os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0755)
23-
CheckAndExit(err)
24-
defer func() { _ = installFile.Close() }()
25-
26-
_, err = io.Copy(installFile, currentFile)
13+
currentPath, err := exec.LookPath(os.Args[0])
2714
CheckAndExit(err)
28-
29-
fmt.Println("Create symbolic file")
30-
CheckAndExit(os.MkdirAll(HooksPath, 0755))
31-
32-
for _, binPath := range BinPaths() {
33-
CheckAndExit(os.Symlink(InstallPath, binPath))
15+
if !Root() {
16+
cmd := exec.Command("sudo", currentPath, "install", "--dir", dir)
17+
cmd.Stdin = os.Stdin
18+
cmd.Stdout = os.Stdout
19+
CheckAndExit(cmd.Run())
20+
} else {
21+
Uninstall(dir)
22+
23+
fmt.Printf("📥 mkdir %s\n", HooksPath)
24+
CheckAndExit(os.MkdirAll(HooksPath, 0755))
25+
26+
fmt.Printf("📥 copy file %s\n", InstallPath)
27+
currentFile, err := os.Open(CurrentPath)
28+
CheckAndExit(err)
29+
defer func() { _ = currentFile.Close() }()
30+
31+
installFile, err := os.OpenFile(InstallPath, os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0755)
32+
CheckAndExit(err)
33+
defer func() { _ = installFile.Close() }()
34+
35+
_, err = io.Copy(installFile, currentFile)
36+
CheckAndExit(err)
37+
38+
var binPaths = []string{
39+
GitCMHookPath,
40+
filepath.Join(dir, "git-ci"),
41+
filepath.Join(dir, "git-feat"),
42+
filepath.Join(dir, "git-fix"),
43+
filepath.Join(dir, "git-docs"),
44+
filepath.Join(dir, "git-style"),
45+
filepath.Join(dir, "git-refactor"),
46+
filepath.Join(dir, "git-test"),
47+
filepath.Join(dir, "git-chore"),
48+
filepath.Join(dir, "git-perf"),
49+
filepath.Join(dir, "git-hotfix"),
50+
filepath.Join(dir, "git-ps"),
51+
}
52+
53+
for _, binPath := range binPaths {
54+
fmt.Printf("📥 install symbolic %s\n", binPath)
55+
CheckAndExit(os.Symlink(InstallPath, binPath))
56+
}
57+
58+
fmt.Printf("📥 config set core.hooksPath %s\n", HooksPath)
59+
MustExec("git", "config", "--global", "core.hooksPath", HooksPath)
3460
}
35-
36-
fmt.Println("Config git")
37-
MustExec("git", "config", "--global", "core.hooksPath", HooksPath)
38-
3961
}

utils/uninstall.go

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,44 @@ package utils
33
import (
44
"fmt"
55
"os"
6+
"os/exec"
7+
"path/filepath"
68
)
79

8-
func Uninstall() {
10+
func Uninstall(dir string) {
911

1012
CheckOS()
11-
CheckRoot()
1213

13-
fmt.Println("Uninstall gitflow-toolkit")
14-
_ = os.RemoveAll(GitFlowToolKitHome)
15-
for _, binPath := range BinPaths() {
16-
_ = os.Remove(binPath)
14+
currentPath, err := exec.LookPath(os.Args[0])
15+
CheckAndExit(err)
16+
if !Root() {
17+
cmd := exec.Command("sudo", currentPath, "uninstall", "--dir", dir)
18+
cmd.Stdin = os.Stdin
19+
cmd.Stdout = os.Stdout
20+
CheckAndExit(cmd.Run())
21+
} else {
22+
fmt.Printf("👉 remove %s\n", GitFlowToolKitHome)
23+
_ = os.RemoveAll(GitFlowToolKitHome)
24+
25+
var binPaths = []string{
26+
filepath.Join(dir, "git-ci"),
27+
filepath.Join(dir, "git-feat"),
28+
filepath.Join(dir, "git-fix"),
29+
filepath.Join(dir, "git-docs"),
30+
filepath.Join(dir, "git-style"),
31+
filepath.Join(dir, "git-refactor"),
32+
filepath.Join(dir, "git-test"),
33+
filepath.Join(dir, "git-chore"),
34+
filepath.Join(dir, "git-perf"),
35+
filepath.Join(dir, "git-hotfix"),
36+
filepath.Join(dir, "git-ps"),
37+
}
38+
39+
for _, binPath := range binPaths {
40+
fmt.Printf("👉 remove %s\n", binPath)
41+
_ = os.Remove(binPath)
42+
}
43+
_ = TryExec("git", "config", "--global", "--unset", "core.hooksPath")
1744
}
18-
_ = TryExec("git", "config", "--global", "--unset", "core.hooksPath")
45+
1946
}

version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v1.0.1
1+
v1.0.2

0 commit comments

Comments
 (0)