Browse Source

add command remove

pull/103/head
Unknown 12 years ago
parent
commit
bf41e75e38
  1. 7
      README.md
  2. 4
      README_ZH.md
  3. 1
      gpm.go
  4. 4
      i18n/en-US/prompt.txt
  5. 2
      i18n/en-US/usage_install.txt
  6. 15
      i18n/en-US/usage_remove.txt
  7. 1
      i18n/zh-CN/prompt.txt
  8. 15
      i18n/zh-CN/usage_remove.txt
  9. 2
      install.go
  10. 119
      remove.go

7
README.md

@ -27,13 +27,13 @@ This application still in experiment, any change could happen, but it doesn't af
## Todo
- Add support for downloading by tag and branch for packages in bitbucket.org, git.oschina.net, gitcafe.com.
- 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.
- After downloaded all packages in bundles or snapshots, need to check if all dependencies have been downloaded as well.
- Develop user source API server template application to support user sources in bundles.
- Add bundle and snapshot parser code for downloading by bundle or snapshot id.
- Command `install` and `remove` Add bundle and snapshot parser code for downloading or removing by bundle or snapshot id.
- Add user system to create, edit, upload, and download bundles or snapshots through gpm client program.
- Download package from code.google.com only support hg as version control system, probably support git and svn.
- Collect download and installation results and report to users in the end.
@ -42,6 +42,9 @@ This application still in experiment, any change could happen, but it doesn't af
- Command `daemon` is for auto-compile web applications when debug it locally.
- Command `update` is for checking updates.
- Command `search` is for searching packages.
- Command `remove` add feature check for dependencies, make sure other packages don't import this one, and give choose for users.
- Command `remove` also need to remove files in `GPPATH/bin` and `GOPATH/pkg`.
- Command `remove` add flag `-d` for removing dependencies at the same time.
- Add feature "struct generator".
- i18n support for Chinese.
- Add built-in application version in order to backup data when users update.

4
README_ZH.md

@ -21,6 +21,10 @@ gpm(Go 包管理工具) 是一款涵盖搜索、安装、更新、分享以
- `build` 编译并安装 Go 包以及其依赖包:该命令从底层调用 `go install` 命令,如果为 main 包,则会将可执行文件从 `GOPATH` 中移至当前目录,可执行文件的名称是由 `go install` 默认指定的当前文件夹名称。
- `install` 下载并安装 Go 包以及其依赖包:您无需安装像 git、hg 或 svn 这类版本控制工具就可以下载您指定的包。该命令也会自动下载相关的依赖包(当您使用集合或快照下载时,不会自动下载依赖包)。目前,该命令支持托管在 `code.google.com`、`github.com`、`launchpad.net` 和 `bitbucket.org` 上的开源项目。
## 已知问题
- 当您使用命令例如 `gpm install -p bitbucket.org/zombiezen/gopdf` 时,你会在安装步骤时得到错误,虽然这是项目的根目录,但是并没有包含任何 Go 源代码,因此您必须使用 `gpm install -p bitbucket.org/zombiezen/gopdf/pdf` 才能正确完成安装。
## 授权许可
[MIT-STYLE](LICENSE)

1
gpm.go

@ -92,6 +92,7 @@ func (c *Command) Runnable() bool {
var commands = []*Command{
cmdBuild,
cmdInstall,
cmdRemove,
}
// getAppPath returns application execute path for current process.

4
i18n/en-US/prompt.txt

@ -10,6 +10,7 @@ UnknownFlag=Unknown flag: %s.
DownloadError=Fail to download package(%s)[ %s ]
NotFoundError=Import path prefix matches known service, but regexp does not.
ErrNoMatch=Unsupported project hosting.
PackageNotFound=Cannot find package: %s.
MovedFile=Moved file from $GOPATH(%s) to current directory(%s).
PureDownload=You enabled pure download.
@ -25,4 +26,5 @@ SkipDownloaded=Skipped downloaded package: %s.
SkipInvalidPath=Skipped invalid import path: %s.
InstallByGoGet=Installing package(%s) through 'go get'.
NoVCSTool=No version control tool is available, pure download enabled!
DownloadStatus=Downloading package: %s.
DownloadStatus=Downloading package: %s.
RemovePackage=Removing package: %s.

2
i18n/en-US/usage_install.txt

@ -25,4 +25,4 @@ For more about specifying packages, see 'go help packages'.
For more about bundle, see 'gpm help bundle'.
For more about snapshot, see 'gpm help snapshot'.
See also: gpm build.
See also: gpm remove.

15
i18n/en-US/usage_remove.txt

@ -0,0 +1,15 @@
remove packages and dependencies|||
Remove removes the packages named by the import paths,
along with their dependencies.
The remove flags are:
The list flags accept a space-separated list of strings. To embed spaces
in an element in the list, surround it with either single or double quotes.
For more about specifying packages, see 'go help packages'.
For more about bundle, see 'gpm help bundle'.
For more about snapshot, see 'gpm help snapshot'.
See also: gpm install.

1
i18n/zh-CN/prompt.txt

@ -10,6 +10,7 @@ UnknownFlag=未知参数: %s.
DownloadError=下载包 (%s) 失败 [ %s ]
NotFoundError=合法的源代码托管平台,但正则匹配失败.
ErrNoMatch=不被支持的源代码托管平台.
PackageNotFound=无法找到包: %s.
MovedFile=成功将文件从 $GOPATH(%s) 移动至当前目录 (%s).
PureDownload=已激活纯净下载模式.

15
i18n/zh-CN/usage_remove.txt

@ -0,0 +1,15 @@
remove packages and dependencies|||
Remove removes the packages named by the import paths,
along with their dependencies.
The remove flags are:
The list flags accept a space-separated list of strings. To embed spaces
in an element in the list, surround it with either single or double quotes.
For more about specifying packages, see 'go help packages'.
For more about bundle, see 'gpm help bundle'.
For more about snapshot, see 'gpm help snapshot'.
See also: gpm install.

2
install.go

@ -20,7 +20,7 @@ import (
var (
isHasGit, isHasHg bool
downloadCache map[string]bool // Saves packages that have downloaded.
downloadCache map[string]bool // Saves packages that have been downloaded.
installGOPATH string // The GOPATH that packages are downloaded to.
)

119
remove.go

@ -0,0 +1,119 @@
// Copyright (c) 2013 GPMGo Members. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package main
import (
"encoding/json"
"fmt"
"os"
"github.com/GPMGo/gpm/doc"
"github.com/GPMGo/gpm/utils"
)
var (
removeCache map[string]bool // Saves packages that have been removed.
)
var cmdRemove = &Command{
UsageLine: "remove [remove flags] <packages|bundles|snapshots>",
}
func init() {
removeCache = make(map[string]bool)
cmdRemove.Run = runRemove
}
func runRemove(cmd *Command, args []string) {
// Check length of arguments.
if len(args) < 1 {
fmt.Printf(fmt.Sprintf("%s\n", promptMsg["NoPackage"]))
return
}
// Generate temporary nodes.
nodes := make([]*doc.Node, len(args))
for i := range nodes {
nodes[i] = new(doc.Node)
nodes[i].ImportPath = args[i]
}
// Removes packages.
removePackages(nodes)
// 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)
return
}
defer fw.Close()
fbytes, err := json.MarshalIndent(&localNodes, "", "\t")
if err != nil {
fmt.Printf(fmt.Sprintf("ERROR: runRemove -> %s\n", promptMsg["ParseJSON"]), err)
return
}
fw.Write(fbytes)
fmt.Println("Well done.")
}
// removePackages removes packages from local file system.
func removePackages(nodes []*doc.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 n.ImportPath[0] == 'B':
case n.ImportPath[0] == 'S':
case utils.IsValidRemotePath(n.ImportPath):
if !removeCache[n.ImportPath] {
// Remove package.
node, imports := removePackage(n)
if len(imports) > 0 {
fmt.Println("Check denpendencies for removing package has not been supported.")
}
// Remove record in local nodes.
if node != nil {
removeNode(node)
}
}
default:
// Invalid import path.
fmt.Printf(fmt.Sprintf("%s\n", promptMsg["SkipInvalidPath"]), n.ImportPath)
}
}
}
// removeNode removes node from local nodes.
func removeNode(n *doc.Node) {
// Check if this node exists.
for i, v := range localNodes {
if n.ImportPath == v.ImportPath {
localNodes = append(localNodes[:i], localNodes[i+1:]...)
return
}
}
}
// removePackage removes package from local file system.
func removePackage(node *doc.Node) (*doc.Node, []string) {
// Find package in GOPATH.
paths := utils.GetGOPATH()
for _, p := range paths {
absPath := p + "/src/" + node.ImportPath + "/"
if utils.IsExist(absPath) {
fmt.Printf(fmt.Sprintf("%s\n", promptMsg["RemovePackage"]), node.ImportPath)
// Remove files.
os.RemoveAll(absPath)
return node, nil
}
}
// Cannot find package.
fmt.Printf(fmt.Sprintf("%s\n", promptMsg["PackageNotFound"]), node.ImportPath)
return nil, nil
}
Loading…
Cancel
Save