Browse Source

fix bug in command remove

pull/103/head
Unknown 12 years ago
parent
commit
d788710f94
  1. 3
      README.md
  2. 2
      README_ZH.md
  3. 2
      build.go
  4. 2
      conf/gpm.toml
  5. 6
      gpm.go
  6. 20
      gpm_test.go
  7. 1
      i18n/zh-CN/prompt.txt
  8. 6
      install.go
  9. 2
      remove.go
  10. 29
      utils/utils.go
  11. 27
      utils/utils_test.go

3
README.md

@ -14,12 +14,14 @@ This application still in experiment, any change could happen, but it doesn't af
## Main features
- Download packages from popular project hosting with/without version control tools.
- Remove packages from local file system.
- More specific examples, see [Quick Start](docs/Quick_Start.md).
## Main commands
- `build` compiles and installs packages and dependencies: basically, it calls `go install` and moves executable to current path from `GOPATH` if any, the executable name is the folder name which is default by `go install`.
- `install` downloads and installs packages and dependencies: you can download packages without version control tools like git, hg, svn, etc. It downloads and installs all packages including all dependencies automatically(except when you use bundle or snapshot id). For now, this command supports `code.google.com`, `github.com`, `launchpad.net`, `bitbucket.org`.
- `remove` removes packages and dependencies: it removes all packages including all dependencies(except when you use bundle or snapshot id).
## Known issues
@ -27,7 +29,6 @@ This application still in experiment, any change could happen, but it doesn't af
## Todo
- Command `remove` is for removing packages.
- Add support for downloading by tag and branch for packages in bitbucket.org, git.oschina.net, gitcafe.com.
- Add gpm working principle design.
- Add support for downloading tarballs from user sources.

2
README_ZH.md

@ -14,12 +14,14 @@ gpm(Go 包管理工具) 是一款涵盖搜索、安装、更新、分享以
## 主要功能
- 无需安装各类复杂的版本控制工具就可以从源代码托管平台下载并安装 Go 包。
- 从本地文件系统中删除 Go 包。
- 更多示例,参见 [快速入门](docs/Quick_Start_ZH.md)
## 主要命令
- `build` 编译并安装 Go 包以及其依赖包:该命令从底层调用 `go install` 命令,如果为 main 包,则会将可执行文件从 `GOPATH` 中移至当前目录,可执行文件的名称是由 `go install` 默认指定的当前文件夹名称。
- `install` 下载并安装 Go 包以及其依赖包:您无需安装像 git、hg 或 svn 这类版本控制工具就可以下载您指定的包。该命令也会自动下载相关的依赖包(当您使用集合或快照下载时,不会自动下载依赖包)。目前,该命令支持托管在 `code.google.com`、`github.com`、`launchpad.net` 和 `bitbucket.org` 上的开源项目。
- `remove` 删除 Go 包及其依赖包:该命令可删除 Go 包及其依赖包(当您使用集合或快照删除时,无法自动删除依赖包)。
## 已知问题

2
build.go

@ -34,7 +34,7 @@ func runBuild(cmd *Command, args []string) {
proName += ".exe"
}
executeGoCommand(cmdArgs)
executeCommand("go", cmdArgs)
// Find executable in GOPATH and copy to current directory.
paths := utils.GetGOPATH()

2
conf/gpm.toml

@ -1,7 +1,7 @@
# This is a configuration file for gpm with toml format.
title = "gpm(Go Package Manager)"
version = "v0.1.4 Build 0522"
version = "v0.1.5 Build 0522"
username = ""
password = ""
user_language = "en-US"

6
gpm.go

@ -396,9 +396,9 @@ func exit() {
os.Exit(exitStatus)
}
// executeGoCommand executes go commands.
func executeGoCommand(args []string) {
cmdExec := exec.Command("go", args...)
// executeCommand executes commands in command line.
func executeCommand(cmd string, args []string) {
cmdExec := exec.Command(cmd, args...)
stdout, err := cmdExec.StdoutPipe()
if err != nil {
fmt.Println(err)

20
gpm_test.go

@ -10,5 +10,23 @@ import (
)
func TestGPM(t *testing.T) {
fmt.Println("gpm v0.1.4 Build 0522")
fmt.Println("gpm v0.1.5 Build 0522")
// Build application.
var args []string
args = append(args, "build")
executeCommand("go", args)
fmt.Println("Start testing command Install...")
args = make([]string, 0)
args = append(args, "install")
args = append(args, "-p")
args = append(args, "bitbucket.org/zombiezen/gopdf/pdf")
executeCommand("gpm", args)
fmt.Println("Start testing command Remove...")
args = make([]string, 0)
args = append(args, "remove")
args = append(args, "bitbucket.org/zombiezen/gopdf/pdf")
executeCommand("gpm", args)
}

1
i18n/zh-CN/prompt.txt

@ -27,3 +27,4 @@ SkipInvalidPath=忽略无效的导入路径: %s.
InstallByGoGet=正在通过 'go get' 安装包 (%s).
NoVCSTool=未找到合适的版本控制工具,已激活纯净下载模式!
DownloadStatus=正在下载包: %s.
RemovePackage=正在删除包: %s.

6
install.go

@ -132,7 +132,7 @@ func runInstall(cmd *Command, args []string) {
for k := range downloadCache {
fmt.Printf(fmt.Sprintf("%s\n", promptMsg["InstallStatus"]), k)
cmdArgs[1] = k
executeGoCommand(cmdArgs)
executeCommand("go", cmdArgs)
}
// Save local nodes to file.
@ -255,7 +255,7 @@ func saveNode(n *doc.Node) {
localNodes = append(localNodes, n)
}
// downloadPackage download package either use version control tools or not.
// downloadPackage downloads package either use version control tools or not.
func downloadPackage(node *doc.Node) (*doc.Node, []string) {
// Check if use version control tools.
switch {
@ -264,7 +264,7 @@ func downloadPackage(node *doc.Node) (*doc.Node, []string) {
fmt.Printf(fmt.Sprintf("%s\n", promptMsg["InstallByGoGet"]), node.ImportPath)
args := checkGoGetFlags()
args = append(args, node.ImportPath)
executeGoCommand(args)
executeCommand("go", args)
return nil, nil
default: // Pure download.
if !cmdInstall.Flags["-p"] {

2
remove.go

@ -104,7 +104,7 @@ func removePackage(node *doc.Node) (*doc.Node, []string) {
// Find package in GOPATH.
paths := utils.GetGOPATH()
for _, p := range paths {
absPath := p + "/src/" + node.ImportPath + "/"
absPath := p + "/src/" + utils.GetProjectPath(node.ImportPath) + "/"
if utils.IsExist(absPath) {
fmt.Printf(fmt.Sprintf("%s\n", promptMsg["RemovePackage"]), node.ImportPath)
// Remove files.

29
utils/utils.go

@ -537,7 +537,34 @@ var standardPath = map[string]bool{
"unsafe": true,
}
// IsGoRepoPath returns true if package is from standard library
// IsGoRepoPath returns true if package is from standard library.
func IsGoRepoPath(importPath string) bool {
return standardPath[importPath]
}
// GetProjectPath returns project path of import path.
func GetProjectPath(importPath string) (projectPath string) {
projectPath = importPath
// Check project hosting.
switch {
case strings.HasPrefix(importPath, "github.com"):
projectPath = joinPath(importPath, 3)
case strings.HasPrefix(importPath, "code.google.com"):
projectPath = joinPath(importPath, 3)
case strings.HasPrefix(importPath, "bitbucket.org"):
projectPath = joinPath(importPath, 3)
case strings.HasPrefix(importPath, "launchpad.net"):
projectPath = joinPath(importPath, 2)
}
return projectPath
}
func joinPath(importPath string, num int) string {
subdirs := strings.Split(importPath, "/")
if len(subdirs) > num {
return strings.Join(subdirs[:num], "/")
}
return importPath
}

27
utils/utils_test.go

@ -8,17 +8,40 @@ import (
"testing"
)
var RemotePaths = []string{
var remotePaths = []string{
"github.com/coocood/qbs",
"code.google.com/p/draw2d",
"launchpad.net/goamz",
"bitbucket.org/gotamer/conv",
}
var importPaths = []string{
"github.com/coocood/qbs/test",
"code.google.com/p/draw2d/test",
"launchpad.net/goamz/test",
"bitbucket.org/gotamer/conv/test",
}
func TestIsValidRemotePath(t *testing.T) {
for _, p := range RemotePaths {
for _, p := range remotePaths {
if !IsValidRemotePath(p) {
t.Errorf("Invalid remote path: %s", p)
}
}
}
func TestGetProjectPath(t *testing.T) {
// Should return same path.
for _, p := range remotePaths {
if p != GetProjectPath(p) {
t.Errorf("Fail to get projet path: %s", p)
}
}
// Should return same path for remote paths.
for i, p := range remotePaths {
if remotePaths[i] != GetProjectPath(p) {
t.Errorf("Fail to verify projet path: %s", p)
}
}
}

Loading…
Cancel
Save