Engine: Engine.Job() never fails, to mimic the os/exec API (and make usage less verbose)
This commit is contained in:
parent
e8491ae54c
commit
a13241d370
3 changed files with 8 additions and 16 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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...)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue