Skip to content

Commit 55bc440

Browse files
authored
Merge pull request #23 from silenceper/f-support-external-cmd
support external cmd
2 parents 8e473a9 + 2549927 commit 55bc440

File tree

6 files changed

+28
-4
lines changed

6 files changed

+28
-4
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ build_pkg: ""
8383
# build tags
8484
build_tags: ""
8585
86+
# Commands that can be executed before running the app
87+
#external_cmd:
88+
# - swag init
89+
8690
# Whether to prohibit automatic operation
8791
disable_run: false
8892

README_ZH_CN.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ build_tags: ""
7070
# 是否禁止自动运行
7171
disable_run: false
7272
73+
#在执行app执行的命令 ,例如 swag init
74+
#external_cmd:
75+
# - swag init
7376
```
7477

7578
## 微信公众号

config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ type config struct {
1919
WatchExts []string `yaml:"watch_exts"`
2020
//需要追加监听的目录,默认是当前文件夹,
2121
WatchPaths []string `yaml:"watch_paths"`
22+
//运行前额外执行的命令
23+
ExternalCmds []string `yaml:"external_cmds"`
2224
//执行时的额外参数
2325
CmdArgs []string `yaml:"cmd_args"`
2426
//构建时的额外参数

example/gowatch.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,7 @@ output: ./example
2525

2626
#build_tags: ""
2727

28+
#external_cmd:
29+
# - go version
30+
2831
disable_run: false

gowatch.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,24 @@ func Start(appname string) {
174174
appname = "./" + appname
175175
}
176176

177-
cmd = exec.Command(appname)
177+
for _, externalCmd := range cfg.ExternalCmds {
178+
log.Infof("Run external cmd '%s'", externalCmd)
179+
cmdArr := strings.Split(externalCmd, " ")
180+
externalCmdExec := exec.Command(cmdArr[0])
181+
externalCmdExec.Env = append(os.Environ(), cfg.Envs...)
182+
externalCmdExec.Args = cmdArr
183+
externalCmdExec.Stdout = os.Stdout
184+
externalCmdExec.Stderr = os.Stderr
185+
err := externalCmdExec.Run()
186+
if err != nil {
187+
panic(err)
188+
}
189+
}
190+
cmd = exec.Command(appname, cfg.CmdArgs...)
178191
cmd.Stdout = os.Stdout
179192
cmd.Stderr = os.Stderr
180-
cmd.Args = append([]string{appname}, cfg.CmdArgs...)
181193
cmd.Env = append(os.Environ(), cfg.Envs...)
182-
log.Infof("Run %s", strings.Join(cmd.Args, " "))
194+
log.Infof("Run '%s'", strings.Join(cmd.Args, " "))
183195
go func() {
184196
_ = cmd.Run()
185197
}()

version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package main
22

33
import "fmt"
44

5-
const version = "1.3"
5+
const version = "1.4"
66

77
func printVersion() {
88
fmt.Println(version)

0 commit comments

Comments
 (0)