RunPreps runs all commands in sequence. Stops if any command returns an error.
( b conf.Block, vars map[string]string, mod *moddwatch.Mod, log termlog.TermLog, notifiers []notify.Notifier, initial bool, )
| 42 | |
| 43 | // RunPreps runs all commands in sequence. Stops if any command returns an error. |
| 44 | func RunPreps( |
| 45 | b conf.Block, |
| 46 | vars map[string]string, |
| 47 | mod *moddwatch.Mod, |
| 48 | log termlog.TermLog, |
| 49 | notifiers []notify.Notifier, |
| 50 | initial bool, |
| 51 | ) error { |
| 52 | sh, err := shell.GetShellName(vars[shellVarName]) |
| 53 | if err != nil { |
| 54 | return err |
| 55 | } |
| 56 | |
| 57 | var modified []string |
| 58 | if mod != nil { |
| 59 | modified = mod.All() |
| 60 | } |
| 61 | vcmd := varcmd.VarCmd{Block: &b, Modified: modified, Vars: vars} |
| 62 | for _, p := range b.Preps { |
| 63 | cmd, err := vcmd.Render(p.Command) |
| 64 | if initial && p.Onchange { |
| 65 | log.Say(niceHeader("skipping prep: ", cmd)) |
| 66 | continue |
| 67 | } |
| 68 | if err != nil { |
| 69 | return err |
| 70 | } |
| 71 | err = RunProc(cmd, sh, b.InDir, log.Stream(niceHeader("prep: ", cmd))) |
| 72 | if err != nil { |
| 73 | if pe, ok := err.(ProcError); ok { |
| 74 | for _, n := range notifiers { |
| 75 | n.Push("modd error", pe.Output, "") |
| 76 | } |
| 77 | } |
| 78 | return err |
| 79 | } |
| 80 | } |
| 81 | return nil |
| 82 | } |