From a13241d370bb9862acdefbc7dbb1e338d9552eaa Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Sat, 26 Oct 2013 17:49:16 -0700 Subject: [PATCH] Engine: Engine.Job() never fails, to mimic the os/exec API (and make usage less verbose) --- docker/docker.go | 5 +---- engine/engine.go | 13 ++++++------- engine/init_test.go | 6 +----- 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/docker/docker.go b/docker/docker.go index d8d30ff341..6540b568fd 100644 --- a/docker/docker.go +++ b/docker/docker.go @@ -71,10 +71,7 @@ func main() { if err != nil { log.Fatal(err) } - job, err := eng.Job("serveapi") - if err != nil { - log.Fatal(err) - } + job := eng.Job("serveapi") job.Setenv("Pidfile", *pidfile) job.Setenv("Root", *flRoot) job.SetenvBool("AutoRestart", *flAutoRestart) diff --git a/engine/engine.go b/engine/engine.go index c912c98cbd..8d67242ca2 100644 --- a/engine/engine.go +++ b/engine/engine.go @@ -64,11 +64,7 @@ func New(root string) (*Engine, error) { // Job creates a new job which can later be executed. // This function mimics `Command` from the standard os/exec package. -func (eng *Engine) Job(name string, args ...string) (*Job, error) { - handler, exists := eng.handlers[name] - if !exists || handler == nil { - return nil, fmt.Errorf("Undefined command; %s", name) - } +func (eng *Engine) Job(name string, args ...string) *Job { job := &Job{ eng: eng, Name: name, @@ -76,8 +72,11 @@ func (eng *Engine) Job(name string, args ...string) (*Job, error) { Stdin: os.Stdin, Stdout: os.Stdout, Stderr: os.Stderr, - handler: handler, } - return job, nil + handler, exists := eng.handlers[name] + if exists { + job.handler = handler + } + return job } diff --git a/engine/init_test.go b/engine/init_test.go index b46e0bc9a1..5c03ded87d 100644 --- a/engine/init_test.go +++ b/engine/init_test.go @@ -38,9 +38,5 @@ func mkEngine(t *testing.T) *Engine { } func mkJob(t *testing.T, name string, args ...string) *Job { - job, err := mkEngine(t).Job(name, args...) - if err != nil { - t.Fatal(err) - } - return job + return mkEngine(t).Job(name, args...) }