Skip to content

Commit

Permalink
refactory trig_async
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelsq committed Jul 2, 2020
1 parent f533f33 commit 9a7eb6a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@ format:
fail: "\u001b[38;5;244m[{{.Time}}] \u001b[38;5;1m[{{.Title}}] \u001b[38;5;238m{{.Message}}\u001b[0m\n"
command_ok: "\u001b[38;5;240m[{{.Time}}] [{{.Title}}] \u001b[0m{{.Message}}\n"
command_err: "\u001b[38;5;240m[{{.Time}}] [{{.Title}}] \u001b[38;5;1m{{.Message}}\u001b[0m\n"
trig: [start, buildNRun] # will run on start
trig_async: true
trig: [start, buildNRun] # will run start and after buildNRun
trig_async: # will run test and async concurrently
- test
- async
env:
- name: PORT
value: 2000
Expand All @@ -84,7 +86,6 @@ rules:
value: development
- name: %{BASE_FILE}% # replace from environment
type: file
trig_async: false
trig:
- done build
- run
Expand All @@ -100,6 +101,8 @@ rules:
type: file
match: _test\.go$
command: go test -cover {PKG}
- name: async
command: echo async
```
Example base.env
Expand Down
4 changes: 2 additions & 2 deletions pkg/wtc/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type Config struct {
Debounce int `yaml:"debounce"`
Rules []*Rule `yaml:"rules"`
Trig []string `yaml:"trig"`
TrigAsync bool `yaml:"trig_async"`
TrigAsync []string `yaml:"trig_async"`
ExitOnTrig bool `yaml:"-"`
Env []*Env `yaml:"env"`
Format struct {
Expand All @@ -27,7 +27,7 @@ type Rule struct {
Debounce *int `yaml:"debounce"`
Command string `yaml:"command"`
Trig []string `yaml:"trig"`
TrigAsync bool `yaml:"trig_async"`
TrigAsync []string `yaml:"trig_async"`
Env []*Env `yaml:"env"`
}

Expand Down
8 changes: 6 additions & 2 deletions pkg/wtc/wtc.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,13 @@ func Start(cfg *Config) {
}()

go func() {
findAndTrig(config.TrigAsync, config.Trig, "./", "./")
if config.ExitOnTrig {
findAndTrig(false, config.Trig, "./", "./")
os.Exit(0)
}

go findAndTrig(true, config.TrigAsync, "./", "./")
findAndTrig(false, config.Trig, "./", "./")
}()

c := make(chan notify.EventInfo)
Expand Down Expand Up @@ -424,7 +427,8 @@ func trig(rule *Rule, pkg, path string) error {
return err
}

findAndTrig(rule.TrigAsync, rule.Trig, pkg, path)
go findAndTrig(true, rule.TrigAsync, pkg, path)
findAndTrig(false, rule.Trig, pkg, path)

return nil
}
Expand Down

0 comments on commit 9a7eb6a

Please sign in to comment.