Browse Source

merge

pull/103/head
Lunny Xiao 12 years ago
parent
commit
5e1040fd19
  1. 20
      build.sh
  2. 25
      cmd/search.go
  3. 19
      cmd/serve.go

20
build.sh

@ -0,0 +1,20 @@
#!/usr/bin/env bash
if [ ! -f build.sh ]; then
echo 'build.sh must be run within its container folder' 1>&2
exit 1
fi
CURDIR=`pwd`
NEWPATH="$GOPATH/src/github.com/gpmgo/gopm"
if [ ! -d "$NEWPATH" ]; then
ln -s $CURDIR $NEWPATH
fi
gofmt -w $CURDIR
cd $NEWPATH
go build
cd $CURDIR
echo 'Build successfully!'

25
cmd/search.go

@ -30,9 +30,6 @@ search packages
The search flags are:
-s
start a search service. This must be run before search a package
-e
search extactly, you should input an exactly package name as keyword
`,
@ -41,14 +38,12 @@ The search flags are:
func init() {
CmdSearch.Run = runSearch
CmdSearch.Flags = map[string]bool{
"-s": false,
"-e": false,
}
}
func printSearchPrompt(flag string) {
switch flag {
case "-s":
doc.ColorLog("[INFO] You enabled start a service.\n")
case "-e":
doc.ColorLog("[INFO] You enabled exactly search.\n")
}
@ -69,22 +64,28 @@ func runSearch(cmd *Command, args []string) {
return
}
var host, port string
host = "localhost"
port = "8991"
autoRun()
if cmd.Flags["-e"] {
search(args[0], true)
search(host, port, args[0], true)
} else {
search(args[0], false)
search(host, port, args[0], false)
}
}
/*
request local or remote search service to find packages according to keyword inputed
*/
func search(keyword string, isExactly bool) {
url := "http://localhost:8991/search?"
func search(host, port, keyword string, isExactly bool) {
url := fmt.Sprintf("http://%v:%v/search?%v", host, port, keyword)
if isExactly {
url = "http://localhost:8991/searche?"
url = fmt.Sprintf("http://%v:%v/searche?%v", host, port, keyword)
}
resp, err := http.Get(url + keyword)
resp, err := http.Get(url)
if err != nil {
doc.ColorLog(err.Error())
return

19
cmd/serve.go

@ -240,11 +240,26 @@ func rmPkg(pkg *Pkg) {
var db *leveldb.DB
// service should be run
func autoRun() {
func autoRun() error {
s, _, _ := runningStatus()
if s == STOP {
os.StartProcess("gopm", []string{"serve", "-l"}, nil)
attr := &os.ProcAttr{
Files: make([]*os.File, 0),
}
_, err := os.StartProcess("./gopm", []string{"serve", "-l"}, attr)
if err != nil {
return err
}
/*f, err := os.OpenFile("~/.gopm/var/pid", os.O_CREATE, 0700)
if err != nil {
return err
}
f.WriteString(fmt.Sprintf("%v,%v,%v", RUNNING, , ))
fmt.Println(p.Pid)*/
}
return nil
}
func runningStatus() (int, int, int) {

Loading…
Cancel
Save