diff --git a/cmd/install.go b/cmd/install.go index d77a9431e..7bbc88bf1 100644 --- a/cmd/install.go +++ b/cmd/install.go @@ -37,6 +37,7 @@ func init() { "-d": false, "-u": false, // Flag for 'go get'. "-e": false, + "-b": false, "-s": false, } } @@ -51,8 +52,6 @@ func printInstallPrompt(flag string) { fmt.Printf(fmt.Sprintf("%s\n", PromptMsg["DownloadOnly"])) case "-e": fmt.Printf(fmt.Sprintf("%s\n", PromptMsg["DownloadExDeps"])) - case "-s": - fmt.Printf(fmt.Sprintf("%s\n", PromptMsg["DownloadFromSrcs"])) } } @@ -123,12 +122,43 @@ func runInstall(cmd *Command, args []string) { installGOPATH = utils.GetBestMatchGOPATH(AppPath) utils.ColorPrint(fmt.Sprintf(fmt.Sprintf("%s\n", PromptMsg["DownloadPath"]), installGOPATH)) - // Generate temporary nodes. - nodes := make([]*node.Node, len(args)) - for i := range nodes { - nodes[i] = new(node.Node) - nodes[i].ImportPath = args[i] + var nodes []*node.Node + // Check if it is a bundle or snapshot. + switch { + case CmdInstall.Flags["-b"]: + bundle := args[0] + // Check local bundles. + nodes = checkLocalBundles(bundle) + if len(nodes) > 0 { + // Check with users if continue. + utils.ColorPrint(fmt.Sprintf(fmt.Sprintf("%s\n", PromptMsg["BundleInfo"]), bundle)) + for _, n := range nodes { + fmt.Printf("[%s] -> %s: %s.\n", n.ImportPath, n.Type, n.Value) + } + fmt.Printf(fmt.Sprintf("%s\n", PromptMsg["ContinueDownload"])) + var option string + fmt.Fscan(os.Stdin, &option) + if strings.ToLower(option) != "y" { + os.Exit(0) + return + } + } else { + // Check from server. + // TODO: api.GetBundleInfo() + fmt.Println("Unable to find bundle, and we cannot check with server right now.") + } + case CmdInstall.Flags["-s"]: + fmt.Println("gopm has not supported snapshot yet.") + // TODO: api.GetSnapshotInfo() + default: + // Generate temporary nodes. + nodes = make([]*node.Node, len(args)) + for i := range nodes { + nodes[i] = new(node.Node) + nodes[i].ImportPath = args[i] + } } + // Download packages. downloadPackages(nodes) @@ -197,33 +227,8 @@ func checkLocalBundles(bundle string) (nodes []*node.Node) { func downloadPackages(nodes []*node.Node) { // Check all packages, they may be bundles, snapshots or raw packages path. for _, n := range nodes { - // Check if it is a bundle or snapshot. - switch { - case strings.HasSuffix(n.ImportPath, ".b"): - l := len(n.ImportPath) - // Check local bundles. - bnodes := checkLocalBundles(n.ImportPath[:l-2]) - if len(bnodes) > 0 { - // Check with users if continue. - 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) - } - fmt.Printf(fmt.Sprintf("%s\n", PromptMsg["ContinueDownload"])) - var option string - fmt.Fscan(os.Stdin, &option) - if strings.ToLower(option) != "y" { - os.Exit(0) - } - downloadPackages(bnodes) - } else { - // Check from server. - // TODO: api.GetBundleInfo() - fmt.Println("Unable to find bundle, and we cannot check with server right now.") - } - case strings.HasSuffix(n.ImportPath, ".s"): - // TODO: api.GetSnapshotInfo() - case utils.IsValidRemotePath(n.ImportPath): + // Check if it is a valid remote path. + if utils.IsValidRemotePath(n.ImportPath) { if !downloadCache[n.ImportPath] { // Download package. nod, imports := downloadPackage(n) @@ -246,7 +251,7 @@ func downloadPackages(nodes []*node.Node) { } else { fmt.Printf(fmt.Sprintf("%s\n", PromptMsg["SkipDownloaded"]), n.ImportPath) } - default: + } else { // Invalid import path. fmt.Printf(fmt.Sprintf("%s\n", PromptMsg["SkipInvalidPath"]), n.ImportPath) } diff --git a/cmd/remove.go b/cmd/remove.go index 3cb6d4df8..82567dda5 100644 --- a/cmd/remove.go +++ b/cmd/remove.go @@ -35,11 +35,41 @@ func runRemove(cmd *Command, args []string) { return } - // Generate temporary nodes. - nodes := make([]*node.Node, len(args)) - for i := range nodes { - nodes[i] = new(node.Node) - nodes[i].ImportPath = args[i] + var nodes []*node.Node + // Check if it is a bundle or snapshot. + switch { + case CmdRemove.Flags["-b"]: + bundle := args[0] + // Check local bundles. + nodes = checkLocalBundles(bundle) + if len(nodes) > 0 { + // Check with users if continue. + utils.ColorPrint(fmt.Sprintf(fmt.Sprintf("%s\n", PromptMsg["BundleInfo"]), bundle)) + for _, n := range nodes { + fmt.Printf("[%s] -> %s: %s.\n", n.ImportPath, n.Type, n.Value) + } + fmt.Printf(fmt.Sprintf("%s\n", PromptMsg["ContinueRemove"])) + var option string + fmt.Fscan(os.Stdin, &option) + if strings.ToLower(option) != "y" { + os.Exit(0) + return + } + } else { + // Check from server. + // TODO: api.GetBundleInfo() + fmt.Println("Unable to find bundle, and we cannot check with server right now.") + } + case CmdRemove.Flags["-s"]: + fmt.Println("gopm has not supported snapshot yet.") + // TODO: api.GetSnapshotInfo() + default: + // Generate temporary nodes. + nodes = make([]*node.Node, len(args)) + for i := range nodes { + nodes[i] = new(node.Node) + nodes[i].ImportPath = args[i] + } } // Removes packages. @@ -65,31 +95,7 @@ func removePackages(nodes []*node.Node) { // Check all packages, they may be bundles, snapshots or raw packages path. for _, n := range nodes { // Check if it is a bundle or snapshot. - switch { - case strings.HasSuffix(n.ImportPath, ".b"): - l := len(n.ImportPath) - // Check local bundles. - bnodes := checkLocalBundles(n.ImportPath[:l-2]) - if len(bnodes) > 0 { - // Check with users if continue. - 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) - } - fmt.Printf(fmt.Sprintf("%s\n", PromptMsg["ContinueRemove"])) - var option string - fmt.Fscan(os.Stdin, &option) - if strings.ToLower(option) != "y" { - os.Exit(0) - } - removePackages(bnodes) - } else { - // Check from server. - // TODO: api.GetBundleInfo() - fmt.Println("Unable to find bundle, and we cannot check with server right now.") - } - case strings.HasSuffix(n.ImportPath, ".s"): - case utils.IsValidRemotePath(n.ImportPath): + if utils.IsValidRemotePath(n.ImportPath) { if !removeCache[n.ImportPath] { // Remove package. nod, imports := removePackage(n) @@ -102,7 +108,7 @@ func removePackages(nodes []*node.Node) { removeNode(nod) } } - default: + } else { // Invalid import path. fmt.Printf(fmt.Sprintf("%s\n", PromptMsg["SkipInvalidPath"]), n.ImportPath) } diff --git a/cmd/search.go b/cmd/search.go index db2347909..d8db58ff3 100644 --- a/cmd/search.go +++ b/cmd/search.go @@ -72,7 +72,7 @@ func runSearch(cmd *Command, args []string) { isWindws := runtime.GOOS == "windows" var buf bytes.Buffer // Print split line for more clear look. - splitLine := "<-----------------------------search results--------------------------->\n" + splitLine := fmt.Sprintf("<-----------------------------%s--------------------------->\n", PromptMsg["SearchResult"]) if !isWindws { splitLine = strings.Replace(splitLine, "<", fmt.Sprintf(utils.PureStartColor, utils.Magenta)+"<", 1) splitLine = strings.Replace(splitLine, ">", ">"+utils.EndColor, 1) diff --git a/i18n/en-US/prompt.txt b/i18n/en-US/prompt.txt index 960524453..ce4c36b62 100644 --- a/i18n/en-US/prompt.txt +++ b/i18n/en-US/prompt.txt @@ -4,7 +4,7 @@ LoadLocalData=Fail to load local data[ %s ] ParseJSON=Fail to parse JSON[ %s ] OpenFile=Fail to open file[ %s ] RemoveFile=Fail to remove file[ %s ] -UnknownCommand=gpm: Unknown command %q. Run 'gpm help' for usage. +UnknownCommand=gopm: Unknown command %q. Run 'gopm help' for usage. MoveFile=Fail to move file from $GOPATH(%s) to current directory(%s). UnknownFlag=Unknown flag: %s. DownloadError=Fail to download package(%s)[ %s ] @@ -17,7 +17,6 @@ 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. -DownloadFromSrcs=You enabled download from sources. NoPackage=Please list at least one package/bundle/snapshot. DownloadPath=Packages will be downloaded to GOPATH(%s). InstallStatus=Installing package: %s. @@ -33,4 +32,5 @@ NoKeyword=Cannot search without a keyword. ContinueRemove=Continue to remove?(Y/n). InvalidPath=Cannot find package in current path. MissingImports=Following packages are missing: -CheckExDeps=You enabled check dependencies in example. \ No newline at end of file +CheckExDeps=You enabled check dependencies in example. +SearchResult=search results \ No newline at end of file diff --git a/i18n/en-US/usage_install.txt b/i18n/en-US/usage_install.txt index fe68a7df3..384ca9eb7 100644 --- a/i18n/en-US/usage_install.txt +++ b/i18n/en-US/usage_install.txt @@ -15,8 +15,10 @@ The install flags are: force to update pakcages. -e download dependencies for examples. + -b + download and install bundle. -s - download from sources. + download and install snapshot. The list flags accept a space-separated list of strings. diff --git a/i18n/en-US/usage_remove.txt b/i18n/en-US/usage_remove.txt index 0ac596717..740de80c8 100644 --- a/i18n/en-US/usage_remove.txt +++ b/i18n/en-US/usage_remove.txt @@ -4,6 +4,10 @@ along with their dependencies. The remove flags are: + -b + remove bundle. + -s + remove snapshot. The list flags accept a space-separated list of strings. diff --git a/i18n/zh-CN/prompt.txt b/i18n/zh-CN/prompt.txt index bfaa7eb6a..0ed3c27d2 100644 --- a/i18n/zh-CN/prompt.txt +++ b/i18n/zh-CN/prompt.txt @@ -4,7 +4,7 @@ LoadLocalData=无法加载本地数据 [ %s ] ParseJSON=JSON 解析失败 [ %s ] OpenFile=文件打开失败 [ %s ] RemoveFile=移除文件失败 [ %s ] -UnknownCommand=gpm: 未知命令 %q. 运行 'gpm help' 获取帮助. +UnknownCommand=gopm: 未知命令 %q. 运行 'gopm help' 获取帮助. MoveFile=从 $GOPATH(%s) 拷贝文件到当前目录 (%s) 失败. UnknownFlag=未知参数: %s. DownloadError=下载包 (%s) 失败 [ %s ] @@ -17,7 +17,6 @@ MovedFile=成功将文件从 $GOPATH(%s) 移动至当前目录 (%s). PureDownload=已激活版本控制下载模式. DownloadOnly=已激活无安装模式. DownloadExDeps=已激活下载示例代码依赖. -DownloadFromSrcs=已激活从用户源下载. NoPackage=请列出至少一个包、集合或快照. DownloadPath=所有包将会被下载至 GOPATH(%s). InstallStatus=正在安装包: %s. @@ -33,4 +32,5 @@ NoKeyword=没有关键字,无法搜索. ContinueRemove=是否继续删除?(Y/n). InvalidPath=无法在当前目录中找到包. MissingImports=下列依赖包未找到: -CheckExDeps=已激活示例代码依赖检查. \ No newline at end of file +CheckExDeps=已激活示例代码依赖检查. +SearchResult=搜索结果 \ No newline at end of file diff --git a/i18n/zh-CN/usage_install.txt b/i18n/zh-CN/usage_install.txt index f478d629b..786b73237 100644 --- a/i18n/zh-CN/usage_install.txt +++ b/i18n/zh-CN/usage_install.txt @@ -13,8 +13,10 @@ Install 命令下载并安装 Go 包及其依赖包. 强制更新包. -e 下载示例代码中的依赖包. + -b + 下载并安装集合. -s - 通过用户源下载. + 下载并安装快照. 多个参数通过空格来间隔. diff --git a/i18n/zh-CN/usage_remove.txt b/i18n/zh-CN/usage_remove.txt index 9f9d530c1..c75e9c69a 100644 --- a/i18n/zh-CN/usage_remove.txt +++ b/i18n/zh-CN/usage_remove.txt @@ -6,6 +6,10 @@ Remove 命令删除 Go 包及其依赖包. 多个参数通过空格来间隔. + -b + 删除集合. + -s + 删除快照. 获取更多有关包的信息,参见 'go help packages'. 获取更多有关集合的信息,参见 'gopm help bundle'.