Просмотр исходного кода

try to clarify autorestart vs restarting.

autorestart restarts when the command exits, otherwise restarts only
happen when the file is saved.
Lucas Stadler лет назад: 11
Родитель
Сommit
eb20545a3c
1 измененных файлов с 10 добавлено и 10 удалено
  1. 10 10
      go/qst.go

+ 10 - 10
go/qst.go

43
}
43
}
44
44
45
var delay = flag.Duration("delay", 1*time.Second, "time to wait until restart")
45
var delay = flag.Duration("delay", 1*time.Second, "time to wait until restart")
46
var autoRestart = flag.Bool("autorestart", true, "restart after command exists")
46
var autoRestart = flag.Bool("autorestart", true, "automatically restart after command exists")
47
var command = flag.String("command", "", "command to run ({file} will be substituted)")
47
var command = flag.String("command", "", "command to run ({file} will be substituted)")
48
48
49
func main() {
49
func main() {
112
}
112
}
113
113
114
type Runner struct {
114
type Runner struct {
115
	cmd        *exec.Cmd
116
	shellCmd   string
117
	started    bool
118
	restart    bool
119
	restarting bool
115
	cmd         *exec.Cmd
116
	shellCmd    string
117
	started     bool
118
	autoRestart bool
119
	restarting  bool
120
}
120
}
121
121
122
func MakeRunner(shellCmd string, restart bool) *Runner {
123
	return &Runner{nil, shellCmd, false, restart, false}
122
func MakeRunner(shellCmd string, autoRestart bool) *Runner {
123
	return &Runner{nil, shellCmd, false, autoRestart, false}
124
}
124
}
125
125
126
func (r *Runner) Start() error {
126
func (r *Runner) Start() error {
146
			log.Printf("%s finished: %s", r.shellCmd, result)
146
			log.Printf("%s finished: %s", r.shellCmd, result)
147
147
148
			time.Sleep(*delay)
148
			time.Sleep(*delay)
149
			if !r.restarting && !r.restart {
149
			if !r.restarting && !r.autoRestart {
150
				r.started = false
150
				r.started = false
151
				break
151
				break
152
			}
152
			}
176
}
176
}
177
177
178
func (r *Runner) Stop() {
178
func (r *Runner) Stop() {
179
	r.restart = false
179
	r.autoRestart = false
180
	r.Kill()
180
	r.Kill()
181
}
181
}
182
182