Selaa lähdekoodia

try to clarify autorestart vs restarting.

autorestart restarts when the command exits, otherwise restarts only
happen when the file is saved.
Lucas Stadler 11 vuotta sitten
vanhempi
commit
eb20545a3c
1 muutettua tiedostoa jossa 10 lisäystä ja 10 poistoa
  1. 10 10
      go/qst.go

+ 10 - 10
go/qst.go

@ -43,7 +43,7 @@ var mappings = map[string]func(string) string{
43 43
}
44 44
45 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 47
var command = flag.String("command", "", "command to run ({file} will be substituted)")
48 48
49 49
func main() {
@ -112,15 +112,15 @@ func runCmd(file string, runner *Runner) {
112 112
}
113 113
114 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 126
func (r *Runner) Start() error {
@ -146,7 +146,7 @@ func (r *Runner) Start() error {
146 146
			log.Printf("%s finished: %s", r.shellCmd, result)
147 147
148 148
			time.Sleep(*delay)
149
			if !r.restarting && !r.restart {
149
			if !r.restarting && !r.autoRestart {
150 150
				r.started = false
151 151
				break
152 152
			}
@ -176,7 +176,7 @@ func (r *Runner) Restart() error {
176 176
}
177 177
178 178
func (r *Runner) Stop() {
179
	r.restart = false
179
	r.autoRestart = false
180 180
	r.Kill()
181 181
}
182 182