From fb80885949075cb51ff2e7a02c96fcb4e8ecbd04 Mon Sep 17 00:00:00 2001 From: mritd Date: Thu, 21 Jun 2018 11:35:02 +0800 Subject: [PATCH] feat(uninstall): add os check add os check Signed-off-by: mritd --- pkg/util/common.go | 7 +++++++ pkg/util/install.go | 46 +++++++++++++++++++------------------------ pkg/util/uninstall.go | 1 + 3 files changed, 28 insertions(+), 26 deletions(-) diff --git a/pkg/util/common.go b/pkg/util/common.go index 96d7344..808c72a 100644 --- a/pkg/util/common.go +++ b/pkg/util/common.go @@ -151,3 +151,10 @@ func OSEditInput() string { return input } + +func CheckOS() { + if runtime.GOOS != "linux" && runtime.GOOS != "darwin" { + fmt.Println("Platform not support!") + os.Exit(1) + } +} diff --git a/pkg/util/install.go b/pkg/util/install.go index fd82f29..cb2033a 100644 --- a/pkg/util/install.go +++ b/pkg/util/install.go @@ -4,42 +4,36 @@ import ( "fmt" "io" "os" - "runtime" ) func Install() { - if runtime.GOOS == "linux" || runtime.GOOS == "darwin" { + Uninstall() - Uninstall() + fmt.Println("Install gitflow-toolkit") + fmt.Println("Create install home dir") + CheckAndExit(os.MkdirAll(GitFlowToolKitHome, 0755)) - fmt.Println("Install gitflow-toolkit") - fmt.Println("Create install home dir") - CheckAndExit(os.MkdirAll(GitFlowToolKitHome, 0755)) + fmt.Println("Copy file to install home") + currentFile, err := os.Open(CurrentPath) + CheckAndExit(err) + defer currentFile.Close() - fmt.Println("Copy file to install home") - currentFile, err := os.Open(CurrentPath) - defer currentFile.Close() - CheckAndExit(err) + installFile, err := os.OpenFile(InstallPath, os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0755) + CheckAndExit(err) + defer installFile.Close() - installFile, err := os.OpenFile(InstallPath, os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0755) - defer installFile.Close() - CheckAndExit(err) - _, err = io.Copy(installFile, currentFile) - CheckAndExit(err) + _, err = io.Copy(installFile, currentFile) + CheckAndExit(err) - fmt.Println("Create symbolic file") - CheckAndExit(os.MkdirAll(HooksPath, 0755)) + fmt.Println("Create symbolic file") + CheckAndExit(os.MkdirAll(HooksPath, 0755)) - for _, binPath := range *BinPaths() { - CheckAndExit(os.Symlink(InstallPath, binPath)) - } + for _, binPath := range *BinPaths() { + CheckAndExit(os.Symlink(InstallPath, binPath)) + } - fmt.Println("Config git") - MustExec("git", "config", "--global", "core.hooksPath", HooksPath) + fmt.Println("Config git") + MustExec("git", "config", "--global", "core.hooksPath", HooksPath) - } else { - fmt.Println("Platform not support!") - os.Exit(1) - } } diff --git a/pkg/util/uninstall.go b/pkg/util/uninstall.go index b567778..7705e78 100644 --- a/pkg/util/uninstall.go +++ b/pkg/util/uninstall.go @@ -7,6 +7,7 @@ import ( func Uninstall() { + CheckOS() CheckRoot() fmt.Println("Uninstall gitflow-toolkit")