增加 command命令变量
This commit is contained in:
parent
73b048ad1a
commit
2a87304923
25
fileboy.go
25
fileboy.go
@ -32,9 +32,10 @@ var (
|
||||
runLock sync.Mutex
|
||||
)
|
||||
|
||||
type wDirState struct {
|
||||
Name string
|
||||
Recursive bool
|
||||
type changeFile struct {
|
||||
Name string
|
||||
changed int64
|
||||
Ext string
|
||||
}
|
||||
|
||||
func parseConfig() {
|
||||
@ -72,22 +73,28 @@ func eventDispatcher(event fsnotify.Event) {
|
||||
}
|
||||
log.Println("stop old process ")
|
||||
}
|
||||
go run()
|
||||
go run(&changeFile{
|
||||
Name: relativePath(projectFolder, event.Name),
|
||||
changed: time.Now().UnixNano(),
|
||||
Ext: ext,
|
||||
})
|
||||
case fsnotify.Remove:
|
||||
case fsnotify.Rename:
|
||||
}
|
||||
}
|
||||
|
||||
func run() {
|
||||
func run(cf *changeFile) {
|
||||
runLock.Lock()
|
||||
defer runLock.Unlock()
|
||||
for i := 0; i < len(cfg.Command.Exec); i++ {
|
||||
carr := cmdParse2Array(cfg.Command.Exec[i])
|
||||
carr := cmdParse2Array(cfg.Command.Exec[i], cf)
|
||||
cmd = exec.Command(carr[0], carr[1:]...)
|
||||
//cmd.SysProcAttr = &syscall.SysProcAttr{CreationFlags: syscall.CREATE_UNICODE_ENVIRONMENT}
|
||||
cmd.Stdin = os.Stdin
|
||||
//cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
cmd.Dir = projectFolder
|
||||
cmd.Env = os.Environ()
|
||||
stdout, err := cmd.StdoutPipe()
|
||||
if err != nil {
|
||||
log.Println("error=>", err.Error())
|
||||
@ -198,7 +205,7 @@ func parseArgs() {
|
||||
if l == 1 {
|
||||
_, err := ioutil.ReadFile(projectFolder + "/filegirl.yaml")
|
||||
if err != nil {
|
||||
log.Println("the filegirl.yaml file is not exist! ", err)
|
||||
log.Println("the filegirl.yaml file does not exist! ", err)
|
||||
fmt.Print(firstRunHelp)
|
||||
fmt.Print(helpStr)
|
||||
return
|
||||
@ -219,7 +226,7 @@ func parseArgs() {
|
||||
return
|
||||
case "exec":
|
||||
parseConfig()
|
||||
run()
|
||||
run(new(changeFile))
|
||||
return
|
||||
default:
|
||||
fmt.Print(helpStr)
|
||||
@ -232,7 +239,7 @@ func show() {
|
||||
fmt.Print(logo)
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
fmt.Println(englishSay[rand.Intn(len(englishSay))], "\r\n")
|
||||
fmt.Println("Version: ", Version, " Author: deng@yoytang.com")
|
||||
fmt.Println("Version: ", Version, " Author: dengsgo@yoytang.com")
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
19
util.go
19
util.go
@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@ -14,17 +15,27 @@ func inStringArray(value string, arr []string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func cmdParse2Array(s string) []string {
|
||||
func cmdParse2Array(s string, cf *changeFile) []string {
|
||||
a := strings.Split(s, " ")
|
||||
r := make([]string, 0)
|
||||
for i := 0; i < len(a); i++ {
|
||||
if ss := strings.Trim(a[i], " "); ss != "" {
|
||||
r = append(r, ss)
|
||||
r = append(r, strParseRealStr(ss, cf))
|
||||
}
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
func strParseRealStr(s string, cf *changeFile) string {
|
||||
return strings.Replace(
|
||||
strings.Replace(
|
||||
strings.Replace(s, "{{file}}", cf.Name, -1),
|
||||
"{{ext}}", cf.Ext, -1,
|
||||
),
|
||||
"{{changed}}", strconv.FormatInt(cf.changed, 10), -1,
|
||||
)
|
||||
}
|
||||
|
||||
func dirParse2Array(s string) []string {
|
||||
a := strings.Split(s, ",")
|
||||
r := make([]string, 0)
|
||||
@ -70,3 +81,7 @@ func arrayRemoveElement(a []string, r string) []string {
|
||||
}
|
||||
return append(a[:i], a[i+1:]...)
|
||||
}
|
||||
|
||||
func relativePath(folder, p string) string {
|
||||
return strings.TrimPrefix(p, folder)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user