|
|
|
@ -3,11 +3,13 @@ package main
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"fmt"
|
|
|
|
|
"io/ioutil"
|
|
|
|
|
"net/http"
|
|
|
|
|
"os"
|
|
|
|
|
"os/exec"
|
|
|
|
|
"path/filepath"
|
|
|
|
|
"strconv"
|
|
|
|
|
"strings"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"github.com/codegangsta/cli"
|
|
|
|
@ -15,6 +17,10 @@ import (
|
|
|
|
|
"github.com/qiniu/log"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
CMDPLUGIN_DIR = filepath.Join(GOSUV_HOME, "cmdplugin")
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func MkdirIfNoExists(dir string) error {
|
|
|
|
|
dir = os.ExpandEnv(dir)
|
|
|
|
|
if _, err := os.Stat(dir); err != nil {
|
|
|
|
@ -23,6 +29,17 @@ func MkdirIfNoExists(dir string) error {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func ShellTestFile(flag string, file string) bool {
|
|
|
|
|
finfo, err := os.Stat(file)
|
|
|
|
|
switch flag {
|
|
|
|
|
case "x":
|
|
|
|
|
if err == nil && (finfo.Mode()&os.ModeExclusive) == 0 {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func chttp(method string, url string, v ...interface{}) (res *JSONResponse, err error) {
|
|
|
|
|
var resp *http.Response
|
|
|
|
|
switch method {
|
|
|
|
@ -224,6 +241,25 @@ func init() {
|
|
|
|
|
Action: ServAction,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
finfos, err := ioutil.ReadDir(CMDPLUGIN_DIR)
|
|
|
|
|
log.Println(err)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
for _, finfo := range finfos {
|
|
|
|
|
if finfo.IsDir() {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
modeExec := os.FileMode(0500)
|
|
|
|
|
if strings.HasPrefix(finfo.Name(), "gosuv-") && (finfo.Mode()&modeExec) == modeExec {
|
|
|
|
|
log.Println(finfo)
|
|
|
|
|
cmdName := string(finfo.Name()[6:])
|
|
|
|
|
app.Commands = append(app.Commands, cli.Command{
|
|
|
|
|
Name: cmdName,
|
|
|
|
|
Usage: "Plugin command",
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|