forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runner.go
52 lines (43 loc) · 1.28 KB
/
runner.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package command_runner
import (
"errors"
. "github.com/cloudfoundry/cli/cf/i18n"
"github.com/cloudfoundry/cli/cf/terminal"
"github.com/cloudfoundry/cli/cf/command_factory"
"github.com/cloudfoundry/cli/cf/requirements"
"github.com/codegangsta/cli"
)
type Runner interface {
RunCmdByName(cmdName string, c *cli.Context) (err error)
}
type ConcreteRunner struct {
cmdFactory command_factory.Factory
requirementsFactory requirements.Factory
ui terminal.UI
}
func NewRunner(cmdFactory command_factory.Factory, requirementsFactory requirements.Factory, ui terminal.UI) (runner ConcreteRunner) {
runner.cmdFactory = cmdFactory
runner.requirementsFactory = requirementsFactory
runner.ui = ui
return
}
func (runner ConcreteRunner) RunCmdByName(cmdName string, c *cli.Context) error {
cmd, err := runner.cmdFactory.GetByCmdName(cmdName)
if err != nil {
runner.ui.Say(T("Error finding command {{.CmdName}}\n", map[string]interface{}{"CmdName": cmdName}))
return err
}
requirements, err := cmd.GetRequirements(runner.requirementsFactory, c)
if err != nil {
return err
}
for _, requirement := range requirements {
success := requirement.Execute()
if !success {
err = errors.New(T("Error in requirement"))
return err
}
}
cmd.Run(c)
return nil
}