Browse Source

add command search

pull/103/head
Unknown 12 years ago
parent
commit
260b0a1c7c
  1. 2
      README.md
  2. 2
      doc/bitbucket.go
  3. 2
      doc/github.go
  4. 6
      doc/google.go
  5. 5
      doc/http.go
  6. 2
      doc/launchpad.go
  7. 3
      gpm.go
  8. 5
      i18n/en-US/prompt.txt
  9. 8
      i18n/en-US/usage_search.txt
  10. 5
      i18n/zh-CN/prompt.txt
  11. 8
      i18n/zh-CN/usage_search.txt
  12. 2
      install.go
  13. 56
      search.go

2
README.md

@ -31,7 +31,6 @@ This application still in experiment, any change could happen, but it doesn't af
### v0.2.*
- Command `search` is for searching packages.
- Add gpm working principle design.
- Command `install` and `remove` Add bundle and snapshot parser code for downloading or removing by bundle or snapshot.
- Command `check` is for checking and downloading all missing dependencies.
@ -44,6 +43,7 @@ This application still in experiment, any change could happen, but it doesn't af
### Future
- Command `search` add flags `-n` and `-o` for number of list items and offset.
- Command `sync` is for sync packages in two computers, support client and server mode through ssh.
- Command `init` is for auto-configuring Go develop environment.
- Command `install` and `remove` and `update` backup data(up to 100 records) before executing.

2
doc/bitbucket.go

@ -81,7 +81,7 @@ func GetBitbucketDoc(client *http.Client, match map[string]string, installGOPATH
// tarball : https://bitbucket.org/{owner}/{repo}/get/{commit}.tar.gz
// Downlaod archive.
p, err := httpGetBytes(client, expand("https://bitbucket.org/{owner}/{repo}/get/{commit}.tar.gz", match), nil)
p, err := HttpGetBytes(client, expand("https://bitbucket.org/{owner}/{repo}/get/{commit}.tar.gz", match), nil)
if err != nil {
return nil, err
}

2
doc/github.go

@ -92,7 +92,7 @@ func GetGithubDoc(client *http.Client, match map[string]string, installGOPATH st
// tarball : https://github.com/{owner}/{repo}/tarball/{sha}
// Downlaod archive.
p, err := httpGetBytes(client, expand("https://github.com/{owner}/{repo}/archive/{sha}.zip", match), nil)
p, err := HttpGetBytes(client, expand("https://github.com/{owner}/{repo}/archive/{sha}.zip", match), nil)
if err != nil {
return nil, err
}

6
doc/google.go

@ -34,7 +34,7 @@ func setupGoogleMatch(match map[string]string) {
func getGoogleVCS(client *http.Client, match map[string]string) error {
// Scrape the HTML project page to find the VCS.
p, err := httpGetBytes(client, expand("http://code.google.com/p/{repo}/source/checkout", match), nil)
p, err := HttpGetBytes(client, expand("http://code.google.com/p/{repo}/source/checkout", match), nil)
if err != nil {
return err
}
@ -67,7 +67,7 @@ func GetGoogleDoc(client *http.Client, match map[string]string, installGOPATH st
rootPath := expand("http://{subrepo}{dot}{repo}.googlecode.com/{vcs}{dir}/", match)
// Scrape the repo browser to find the project revision and individual Go files.
p, err := httpGetBytes(client, rootPath+"?r="+node.Value, nil)
p, err := HttpGetBytes(client, rootPath+"?r="+node.Value, nil)
if err != nil {
return nil, err
}
@ -171,7 +171,7 @@ func GetGoogleDoc(client *http.Client, match map[string]string, installGOPATH st
func downloadFiles(client *http.Client, match map[string]string, rootPath, installPath, commit string, dirs []string) error {
for _, d := range dirs {
p, err := httpGetBytes(client, rootPath+d+"?r="+commit, nil)
p, err := HttpGetBytes(client, rootPath+d+"?r="+commit, nil)
if err != nil {
return err
}

5
doc/http.go

@ -50,9 +50,8 @@ var (
HttpClient = &http.Client{Transport: httpTransport}
)
// httpGet gets the specified resource. ErrNotFound is returned if the server
// responds with status 404.
func httpGetBytes(client *http.Client, url string, header http.Header) ([]byte, error) {
// HttpGetBytes returns page data in []byte.
func HttpGetBytes(client *http.Client, url string, header http.Header) ([]byte, error) {
rc, err := httpGet(client, url, header)
if err != nil {
return nil, err

2
doc/launchpad.go

@ -50,7 +50,7 @@ func GetLaunchpadDoc(client *http.Client, match map[string]string, installGOPATH
}
// Scrape the repo browser to find the project revision and individual Go files.
p, err := httpGetBytes(client, downloadPath, nil)
p, err := HttpGetBytes(client, downloadPath, nil)
if err != nil {
return nil, err
}

3
gpm.go

@ -46,7 +46,7 @@ type tomlConfig struct {
}
type flagEnable struct {
Build, Install []string
Build, Install, Search []string
}
type account struct {
@ -101,6 +101,7 @@ func (c *Command) Runnable() bool {
// The order here is the order in which they are printed by 'gpm help'.
var commands = []*Command{
cmdBuild,
cmdSearch,
cmdInstall,
cmdRemove,
}

5
i18n/en-US/prompt.txt

@ -12,7 +12,7 @@ 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).
MovedFile=SUCCESS: Moved file from $GOPATH(%s) to current directory(%s).
PureDownload=You enabled pure download.
DownloadOnly=You enabled download without installing.
DownloadExDeps=You enabled download dependencies in example.
@ -27,4 +27,5 @@ 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.
RemovePackage=Removing package: %s.
RemovePackage=Removing package: %s.
NoKeyword=Cannot search without a keyword.

8
i18n/en-US/usage_search.txt

@ -0,0 +1,8 @@
search packages|||
Search searchs packages by keyword.
The search 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.

5
i18n/zh-CN/prompt.txt

@ -12,7 +12,7 @@ NotFoundError=合法的源代码托管平台,但正则匹配失败.
ErrNoMatch=不被支持的源代码托管平台.
PackageNotFound=无法找到包: %s.
MovedFile=成功将文件从 $GOPATH(%s) 移动至当前目录 (%s).
MovedFile=SUCCESS: 成功将文件从 $GOPATH(%s) 移动至当前目录 (%s).
PureDownload=已激活纯净下载模式.
DownloadOnly=已激活无安装模式.
DownloadExDeps=已激活下载示例代码依赖.
@ -27,4 +27,5 @@ SkipInvalidPath=忽略无效的导入路径: %s.
InstallByGoGet=正在通过 'go get' 安装包 (%s).
NoVCSTool=未找到合适的版本控制工具,已激活纯净下载模式!
DownloadStatus=正在下载包: %s.
RemovePackage=正在删除包: %s.
RemovePackage=正在删除包: %s.
NoKeyword=没有关键字,无法搜索.

8
i18n/zh-CN/usage_search.txt

@ -0,0 +1,8 @@
search packages|||
Search searchs packages by keyword.
The search 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.

2
install.go

@ -74,7 +74,7 @@ func checkFlags(flags map[string]bool, enable []string, args []string, print fun
// Check if it a valid flag.
if v, ok := flags[f]; ok {
flags[f] = !v
if v {
if !v {
print(f)
} else {
fmt.Println("DISABLE: " + f)

56
search.go

@ -0,0 +1,56 @@
// 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 (
"fmt"
"strings"
"github.com/GPMGo/gpm/doc"
)
var cmdSearch = &Command{
UsageLine: "search [search flags] <keyword>",
}
func init() {
cmdSearch.Run = runSearch
}
// printSearchPrompt prints prompt information to users to
// let them know what's going on.
func printSearchPrompt(flag string) {
switch flag {
}
}
func runSearch(cmd *Command, args []string) {
// Check flags.
num := checkFlags(cmd.Flags, config.AutoEnable.Search, args, printSearchPrompt)
if num == -1 {
return
}
args = args[num:]
// Check length of arguments.
if len(args) < 1 {
fmt.Printf(fmt.Sprintf("%s\n", promptMsg["NoKeyword"]))
return
}
// Search from server, and list results.
results, _ := doc.HttpGetBytes(doc.HttpClient, "http://gowalker.org/search?raw=true&q="+args[0], nil)
pkgs := strings.Split(string(results), "|||")
for _, p := range pkgs {
i := strings.Index(p, "$")
if i > -1 {
fmt.Println("-> " + p[:i]) // Package import path.
if len(p) > (i + 1) {
fmt.Println(" " + p[i+1:]) // Synopsis。
}
}
}
}
Loading…
Cancel
Save