Skip to content

Commit fb80885

Browse files
author
mritd
committed
feat(uninstall): add os check
add os check Signed-off-by: mritd <mritd1234@gmail.com>
1 parent 7add5b9 commit fb80885

File tree

3 files changed

+28
-26
lines changed

3 files changed

+28
-26
lines changed

pkg/util/common.go

+7
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,10 @@ func OSEditInput() string {
151151

152152
return input
153153
}
154+
155+
func CheckOS() {
156+
if runtime.GOOS != "linux" && runtime.GOOS != "darwin" {
157+
fmt.Println("Platform not support!")
158+
os.Exit(1)
159+
}
160+
}

pkg/util/install.go

+20-26
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,36 @@ import (
44
"fmt"
55
"io"
66
"os"
7-
"runtime"
87
)
98

109
func Install() {
1110

12-
if runtime.GOOS == "linux" || runtime.GOOS == "darwin" {
11+
Uninstall()
1312

14-
Uninstall()
13+
fmt.Println("Install gitflow-toolkit")
14+
fmt.Println("Create install home dir")
15+
CheckAndExit(os.MkdirAll(GitFlowToolKitHome, 0755))
1516

16-
fmt.Println("Install gitflow-toolkit")
17-
fmt.Println("Create install home dir")
18-
CheckAndExit(os.MkdirAll(GitFlowToolKitHome, 0755))
17+
fmt.Println("Copy file to install home")
18+
currentFile, err := os.Open(CurrentPath)
19+
CheckAndExit(err)
20+
defer currentFile.Close()
1921

20-
fmt.Println("Copy file to install home")
21-
currentFile, err := os.Open(CurrentPath)
22-
defer currentFile.Close()
23-
CheckAndExit(err)
22+
installFile, err := os.OpenFile(InstallPath, os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0755)
23+
CheckAndExit(err)
24+
defer installFile.Close()
2425

25-
installFile, err := os.OpenFile(InstallPath, os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0755)
26-
defer installFile.Close()
27-
CheckAndExit(err)
28-
_, err = io.Copy(installFile, currentFile)
29-
CheckAndExit(err)
26+
_, err = io.Copy(installFile, currentFile)
27+
CheckAndExit(err)
3028

31-
fmt.Println("Create symbolic file")
32-
CheckAndExit(os.MkdirAll(HooksPath, 0755))
29+
fmt.Println("Create symbolic file")
30+
CheckAndExit(os.MkdirAll(HooksPath, 0755))
3331

34-
for _, binPath := range *BinPaths() {
35-
CheckAndExit(os.Symlink(InstallPath, binPath))
36-
}
32+
for _, binPath := range *BinPaths() {
33+
CheckAndExit(os.Symlink(InstallPath, binPath))
34+
}
3735

38-
fmt.Println("Config git")
39-
MustExec("git", "config", "--global", "core.hooksPath", HooksPath)
36+
fmt.Println("Config git")
37+
MustExec("git", "config", "--global", "core.hooksPath", HooksPath)
4038

41-
} else {
42-
fmt.Println("Platform not support!")
43-
os.Exit(1)
44-
}
4539
}

pkg/util/uninstall.go

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
func Uninstall() {
99

10+
CheckOS()
1011
CheckRoot()
1112

1213
fmt.Println("Uninstall gitflow-toolkit")

0 commit comments

Comments
 (0)