Skip to content

Commit

Permalink
support "-p" for postponing first run
Browse files Browse the repository at this point in the history
  • Loading branch information
mitranim committed Feb 8, 2023
1 parent a5bfab2 commit 36c8536
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
9 changes: 7 additions & 2 deletions gow_main.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,20 +135,25 @@ func (self *Main) WatchRun() {
}

func (self *Main) CmdRun() {
for {
if !self.Opt.Postpone {
self.Cmd.Restart()
}

for {
sel:
select {
case <-self.ChanRestart:
self.Opt.TermClear()
continue
break sel

case val := <-self.ChanKill:
self.Cmd.Broadcast(val)
self.Deinit()
gg.Nop1(syscall.Kill(os.Getpid(), val))
return
}

self.Cmd.Restart()
}
}

Expand Down
18 changes: 9 additions & 9 deletions gow_misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ var (
).Replace
)

/**
Making `.main` private reduces the chance of accidental cyclic walking by
reflection tools such as pretty printers.
*/
type Mained struct{ main *Main }

func (self *Mained) Init(val *Main) { self.main = val }
func (self *Mained) Main() *Main { return self.main }

/**
Implemented by `notify.EventInfo`.
Path must be an absolute filesystem path.
Expand Down Expand Up @@ -103,12 +112,3 @@ func withNewline[A ~string](val A) A {
}
return val + A(gg.Newline)
}

/**
The field is private to avoid accidental cyclic walking by reflection-based
code, not for pointless "encapsulation".
*/
type Mained struct{ main *Main }

func (self *Mained) Init(val *Main) { self.main = val }
func (self *Mained) Main() *Main { return self.main }
3 changes: 2 additions & 1 deletion gow_opt.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ type Opt struct {
Sep FlagStrMultiline `flag:"-S" desc:"Separator printed after each run; multi; supports \\n."`
Trace bool `flag:"-t" desc:"Print error trace on exit. Useful for debugging gow."`
RawEcho bool `flag:"-re" init:"true" desc:"In raw mode, echo stdin to stdout like most apps."`
Lazy bool `flag:"-l" desc:"Lazy mode: no restart when subprocess is running."`
Lazy bool `flag:"-l" desc:"Lazy mode: restart only when subprocess is not running."`
Postpone bool `flag:"-p" desc:"Postpone first run until FS event or manual ^R."`
Extensions FlagExtensions `flag:"-e" init:"go,mod" desc:"Extensions to watch; multi."`
Watch FlagWatch `flag:"-w" init:"." desc:"Paths to watch, relative to CWD; multi."`
IgnoredPaths FlagIgnoredPaths `flag:"-i" desc:"Ignored paths, relative to CWD; multi."`
Expand Down
4 changes: 2 additions & 2 deletions gow_stdio.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,13 @@ func (self *Stdio) OnCodeSig(code byte, sig syscall.Signal, desc string) {
main := self.Main()

if self.IsCodeRepeated(code) {
log.Printf(`received %[1]v%[1]v, shutting down`, desc)
log.Println(`received ` + desc + desc + `, shutting down`)
main.Kill(sig)
return
}

if main.Opt.Verb {
log.Printf(`received %[1]v, stopping subprocess`, desc)
log.Println(`received ` + desc + `, stopping subprocess`)
}
main.Cmd.Broadcast(sig)
}
Expand Down

0 comments on commit 36c8536

Please sign in to comment.