Engine: Engine.Job() never fails, to mimic the os/exec API (and make usage less verbose)

This commit is contained in:
Solomon Hykes 2013-10-26 17:49:16 -07:00
parent e8491ae54c
commit a13241d370
3 changed files with 8 additions and 16 deletions

View file

@ -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)

View file

@ -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
}

View file

@ -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...)
}