mirror of https://github.com/gogits/gogs.git
Unknown
12 years ago
13 changed files with 90 additions and 16 deletions
@ -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. |
@ -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. |
@ -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…
Reference in new issue