diff --git a/build.go b/build.go index 249061617..d40bde381 100644 --- a/build.go +++ b/build.go @@ -57,13 +57,13 @@ func runBuild(cmd *Command, args []string) { if utils.IsExist(wd + "/" + proName) { err := os.Remove(wd + "/" + proName) if err != nil { - fmt.Printf(fmt.Sprintf("ERROR: %s\n", promptMsg["RemoveFile"]), err) + utils.ColorPrint(fmt.Sprintf(fmt.Sprintf("[ERROR] %s\n", promptMsg["RemoveFile"]), err)) return } } err := os.Rename(v+"/bin/"+proName, wd+"/"+proName) if err == nil { - fmt.Printf(fmt.Sprintf("%s\n", promptMsg["MovedFile"]), v, wd) + utils.ColorPrint(fmt.Sprintf(fmt.Sprintf("$ %s\n", promptMsg["MovedFile"]), v, wd)) // Check if need to run program. if cmdBuild.Flags["-r"] { cmdArgs = make([]string, 0) diff --git a/check.go b/check.go index a5d227bc0..873e4542d 100644 --- a/check.go +++ b/check.go @@ -52,7 +52,7 @@ func runCheck(cmd *Command, args []string) { importPath := wd[len(gopath):] imports, err := checkImportsByRoot(wd+"/", importPath) if err != nil { - fmt.Printf(fmt.Sprintf("runCheck -> %s\n", promptMsg["CheckImports"]), err) + utils.ColorPrint(fmt.Sprintf(fmt.Sprintf("runCheck -> %s\n", promptMsg["CheckImports"]), err)) return } @@ -98,7 +98,7 @@ func runCheck(cmd *Command, args []string) { } installGOPATH = utils.GetBestMatchGOPATH(appPath) - fmt.Printf(fmt.Sprintf("%s\n", promptMsg["DownloadPath"]), installGOPATH) + utils.ColorPrint(fmt.Sprintf(fmt.Sprintf("%s\n", promptMsg["DownloadPath"]), installGOPATH)) // Generate temporary nodes. nodes := make([]*doc.Node, len(uninstallList)) for i := range nodes { @@ -166,7 +166,7 @@ func checkIsExistWithVCS(path string) bool { // Check if only has VCS folder. dirs, err := utils.GetDirsInfo(path) if err != nil { - fmt.Printf("checkIsExistWithVCS -> [ %s ]", err) + utils.ColorPrint(fmt.Sprintf("[ERROR] checkIsExistWithVCS -> [ %s ]", err)) return false } diff --git a/gopm b/gopm new file mode 100755 index 000000000..115d5a13b Binary files /dev/null and b/gopm differ diff --git a/i18n/en-US/prompt.txt b/i18n/en-US/prompt.txt index 63f065c50..960524453 100644 --- a/i18n/en-US/prompt.txt +++ b/i18n/en-US/prompt.txt @@ -13,7 +13,7 @@ ErrNoMatch=Unsupported project hosting. PackageNotFound=Cannot find package: %s. CheckImports=Fail to check dependencies[ %s ] -MovedFile=SUCCESS: Moved file from $GOPATH(%s) to current directory(%s). +MovedFile=Moved file from $GOPATH(%s) to current directory(%s). PureDownload=You enabled download with version control. DownloadOnly=You enabled download without installing. DownloadExDeps=You enabled download dependencies in example. diff --git a/i18n/zh-CN/prompt.txt b/i18n/zh-CN/prompt.txt index 546ed4bad..bfaa7eb6a 100644 --- a/i18n/zh-CN/prompt.txt +++ b/i18n/zh-CN/prompt.txt @@ -13,7 +13,7 @@ ErrNoMatch=不被支持的源代码托管平台. PackageNotFound=无法找到包: %s. CheckImports=一百遍检查失败 [ %s ] -MovedFile=SUCCESS: 成功将文件从 $GOPATH(%s) 移动至当前目录 (%s). +MovedFile=成功将文件从 $GOPATH(%s) 移动至当前目录 (%s). PureDownload=已激活版本控制下载模式. DownloadOnly=已激活无安装模式. DownloadExDeps=已激活下载示例代码依赖. diff --git a/install.go b/install.go index 891f33bc5..df15c2a0b 100644 --- a/install.go +++ b/install.go @@ -120,7 +120,7 @@ func runInstall(cmd *Command, args []string) { checkVCSTool() installGOPATH = utils.GetBestMatchGOPATH(appPath) - fmt.Printf(fmt.Sprintf("%s\n", promptMsg["DownloadPath"]), installGOPATH) + utils.ColorPrint(fmt.Sprintf(fmt.Sprintf("%s\n", promptMsg["DownloadPath"]), installGOPATH)) // Generate temporary nodes. nodes := make([]*doc.Node, len(args)) @@ -153,13 +153,13 @@ func runInstall(cmd *Command, args []string) { // Save local nodes to file. fw, err := os.Create(appPath + "data/nodes.json") if err != nil { - fmt.Printf(fmt.Sprintf("ERROR: runInstall -> %s\n", promptMsg["OpenFile"]), err) + utils.ColorPrint(fmt.Sprintf(fmt.Sprintf("[ERROR] runInstall -> %s\n", promptMsg["OpenFile"]), err)) return } defer fw.Close() fbytes, err := json.MarshalIndent(&localNodes, "", "\t") if err != nil { - fmt.Printf(fmt.Sprintf("ERROR: runInstall -> %s\n", promptMsg["ParseJSON"]), err) + utils.ColorPrint(fmt.Sprintf(fmt.Sprintf("[ERROR] runInstall -> %s\n", promptMsg["ParseJSON"]), err)) return } fw.Write(fbytes) @@ -204,7 +204,7 @@ func downloadPackages(nodes []*doc.Node) { bnodes := checkLocalBundles(n.ImportPath[:l-2]) if len(bnodes) > 0 { // Check with users if continue. - fmt.Printf(fmt.Sprintf("%s\n", promptMsg["BundleInfo"]), n.ImportPath[:l-2]) + utils.ColorPrint(fmt.Sprintf(fmt.Sprintf("%s\n", promptMsg["BundleInfo"]), n.ImportPath[:l-2])) for _, bn := range bnodes { fmt.Printf("[%s] -> %s: %s.\n", bn.ImportPath, bn.Type, bn.Value) } @@ -293,7 +293,7 @@ func downloadPackage(node *doc.Node) (*doc.Node, []string) { imports, err := pureDownload(node) if err != nil { - fmt.Printf(fmt.Sprintf("%s\n", promptMsg["DownloadError"]), node.ImportPath, err) + utils.ColorPrint(fmt.Sprintf(fmt.Sprintf("[ERROR] %s\n", promptMsg["DownloadError"]), node.ImportPath, err)) return nil, nil } diff --git a/remove.go b/remove.go index fc5898ad2..f955e16d3 100644 --- a/remove.go +++ b/remove.go @@ -48,13 +48,13 @@ func runRemove(cmd *Command, args []string) { // Save local nodes to file. fw, err := os.Create(appPath + "data/nodes.json") if err != nil { - fmt.Printf(fmt.Sprintf("ERROR: runRemove -> %s\n", promptMsg["OpenFile"]), err) + utils.ColorPrint(fmt.Sprintf(fmt.Sprintf("[ERROR] runRemove -> %s\n", promptMsg["OpenFile"]), err)) return } defer fw.Close() fbytes, err := json.MarshalIndent(&localNodes, "", "\t") if err != nil { - fmt.Printf(fmt.Sprintf("ERROR: runRemove -> %s\n", promptMsg["ParseJSON"]), err) + utils.ColorPrint(fmt.Sprintf(fmt.Sprintf("[ERROR] runRemove -> %s\n", promptMsg["ParseJSON"]), err)) return } fw.Write(fbytes) @@ -72,7 +72,7 @@ func removePackages(nodes []*doc.Node) { bnodes := checkLocalBundles(n.ImportPath[:l-2]) if len(bnodes) > 0 { // Check with users if continue. - fmt.Printf(fmt.Sprintf("%s\n", promptMsg["BundleInfo"]), n.ImportPath[:l-2]) + utils.ColorPrint(fmt.Sprintf(fmt.Sprintf("%s\n", promptMsg["BundleInfo"]), n.ImportPath[:l-2])) for _, bn := range bnodes { fmt.Printf("[%s] -> %s: %s.\n", bn.ImportPath, bn.Type, bn.Value) } diff --git a/utils/utils.go b/utils/utils.go index 910dac3ae..362919d6b 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -15,7 +15,6 @@ import ( const ( PureStartColor = "\033[%dm" - StartColor = "(\033[%dm" Gray = uint8(90) Red = uint8(91) Green = uint8(92) @@ -31,10 +30,12 @@ const ( func ColorPrint(log string) { // Make sure it's not windows. if runtime.GOOS != "windows" { - log = strings.Replace(log, "[", fmt.Sprintf(StartColor, Red), -1) + log = strings.Replace(log, "[", fmt.Sprintf("[\033[%dm", Red), -1) log = strings.Replace(log, "]", EndColor+"]", -1) - log = strings.Replace(log, "(", fmt.Sprintf(StartColor, Green), -1) + log = strings.Replace(log, "(", fmt.Sprintf("(\033[%dm", Yellow), -1) log = strings.Replace(log, ")", EndColor+")", -1) + log = strings.Replace(log, "<", fmt.Sprintf("[\033[%dm", Green), -1) + log = strings.Replace(log, ">$", EndColor+"]", -1) } fmt.Print(log) }