From 5e1040fd19be92586aa6646774f79d2f90228e05 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 27 Aug 2013 15:14:41 +0800 Subject: [PATCH] merge --- build.sh | 20 ++++++++++++++++++++ cmd/search.go | 25 +++++++++++++------------ cmd/serve.go | 19 +++++++++++++++++-- 3 files changed, 50 insertions(+), 14 deletions(-) create mode 100755 build.sh diff --git a/build.sh b/build.sh new file mode 100755 index 000000000..0c59d1202 --- /dev/null +++ b/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!' diff --git a/cmd/search.go b/cmd/search.go index 58864f449..917a4b04c 100644 --- a/cmd/search.go +++ b/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 diff --git a/cmd/serve.go b/cmd/serve.go index aad54f252..cb7cb53a9 100644 --- a/cmd/serve.go +++ b/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) {