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