From cb83f44c25ad9839014e18dd4a7aa64aa0f76e53 Mon Sep 17 00:00:00 2001 From: EchoJamie Date: Mon, 1 Jul 2024 19:33:34 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20isx=20clone=20=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E5=88=B0=E5=BD=93=E5=89=8D=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/clone.go | 17 ++++++++++++++--- common/color.go | 47 +++++++++++++++++++++++++++++++++++++++++++++++ common/common.go | 9 +++++++++ 3 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 common/color.go diff --git a/cmd/clone.go b/cmd/clone.go index 850a74c..9f596ca 100644 --- a/cmd/clone.go +++ b/cmd/clone.go @@ -65,10 +65,21 @@ func inputProjectNumber() { } func inputProjectPath() { - + currentWorkDir := common.CurrentWorkDir() // 输入安装路径 - fmt.Print("请输入安装路径:") - fmt.Scanln(&projectPath) + fmt.Printf("是否安装在当前路径(%s)下? (y/n) ", common.WhiteText(currentWorkDir)) + var flag = "" + fmt.Scanln(&flag) + flag = strings.Trim(flag, " ") + for flag == "y" || flag == "n" { + if flag == "y" { + projectPath = currentWorkDir + } + if flag == "n" { + fmt.Print("请输入安装路径:") + fmt.Scanln(&projectPath) + } + } // 支持克隆路径替换~为当前用户目录 if strings.HasPrefix(projectPath, "~/") { diff --git a/common/color.go b/common/color.go new file mode 100644 index 0000000..1f6ba7e --- /dev/null +++ b/common/color.go @@ -0,0 +1,47 @@ +/* +Copyright © 2024 jamie HERE +*/ +package common + +const ( + Reset = "\033[0m" + Red = "\033[31m" + Green = "\033[32m" + Yellow = "\033[33m" + Blue = "\033[34m" + Purple = "\033[35m" + Cyan = "\033[36m" + White = "\033[37m" +) + +func textWithColor(color, text string) string { + return color + text + Reset +} + +func RedText(text string) string { + return textWithColor(Red, text) +} + +func GreenText(text string) string { + return textWithColor(Green, text) +} + +func YellowText(text string) string { + return textWithColor(Yellow, text) +} + +func BlueText(text string) string { + return textWithColor(Blue, text) +} + +func PurpleText(text string) string { + return textWithColor(Purple, text) +} + +func CyanText(text string) string { + return textWithColor(Cyan, text) +} + +func WhiteText(text string) string { + return textWithColor(White, text) +} diff --git a/common/common.go b/common/common.go index a8bd081..ccf9ce6 100644 --- a/common/common.go +++ b/common/common.go @@ -17,3 +17,12 @@ func HomeDir() string { } return home } + +func CurrentWorkDir() string { + dir, err := os.Getwd() + if err != nil { + fmt.Println(err) + os.Exit(1) + } + return dir +}