Skip to content
This repository has been archived by the owner on Apr 21, 2019. It is now read-only.

Commit

Permalink
exec: refactor Applier to Apply function
Browse files Browse the repository at this point in the history
Conceptually, Apply is an operation, not a stateful object.  This new
API makes it easier to hold it wrong.  Further, this enabled me to
create a new internal type: job.  jobs are created with only the state
that is necessary for a single resource, so it is much easier to
identify unnecessary shared state.
  • Loading branch information
zombiezen committed Jan 25, 2017
1 parent f92d09d commit af53d88
Show file tree
Hide file tree
Showing 4 changed files with 210 additions and 159 deletions.
17 changes: 8 additions & 9 deletions exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,22 @@ func usage() {

func main() {
log := new(logger)
app := &execlib.Applier{
opts := &execlib.Options{
Log: log,
}
simulate := flag.Bool("n", false, "dry-run")
flag.BoolVar(&log.quiet, "q", false, "suppress info messages and failure output")
logCommands := flag.Bool("s", false, "show commands run in the log")
flag.IntVar(&app.ConcurrentJobs, "j", 1, "set the maximum number of resources to apply simultaneously")
flag.StringVar(&app.Bash, "bash", execlib.DefaultBashPath, "path to bash shell")
flag.IntVar(&opts.ConcurrentJobs, "j", 1, "set the maximum number of resources to apply simultaneously")
flag.StringVar(&opts.Bash, "bash", execlib.DefaultBashPath, "path to bash shell")
flag.Parse()
var sys system.System = system.Local{}
if *simulate {
app.System = simulatedSystem{}
} else {
app.System = system.Local{}
sys = simulatedSystem{}
}
if *logCommands {
app.System = sysLogger{
System: app.System,
sys = sysLogger{
System: sys,
log: log,
}
}
Expand Down Expand Up @@ -91,7 +90,7 @@ func main() {
os.Exit(2)
}

if err := app.Apply(ctx, cat); err != nil {
if err := execlib.Apply(ctx, sys, cat, opts); err != nil {
log.Fatal(ctx, err)
}
}
Expand Down
Loading

0 comments on commit af53d88

Please sign in to comment.