forked from cloudfoundry/bosh-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deployment.go
68 lines (50 loc) · 1.4 KB
/
deployment.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package cmd
import (
cmdconf "github.com/cloudfoundry/bosh-cli/cmd/config"
boshdir "github.com/cloudfoundry/bosh-cli/director"
biui "github.com/cloudfoundry/bosh-cli/ui"
)
type DeploymentCmd struct {
sessionFactory func(cmdconf.Config) Session
config cmdconf.Config
ui biui.UI
}
func NewDeploymentCmd(
sessionFactory func(cmdconf.Config) Session,
config cmdconf.Config,
ui biui.UI,
) DeploymentCmd {
return DeploymentCmd{sessionFactory: sessionFactory, config: config, ui: ui}
}
func (c DeploymentCmd) Run(opts DeploymentOpts) error {
if len(opts.Args.NameOrPath) == 0 {
return c.show()
}
return c.set(opts)
}
func (c DeploymentCmd) show() error {
sess := c.sessionFactory(c.config)
deployment, err := sess.Deployment()
if err != nil {
return err
}
c.ui.PrintLinef("Current deployment is '%s'", deployment.Name())
_ = DeploymentsTable{[]boshdir.Deployment{deployment}, c.ui}.Print()
return nil
}
func (c DeploymentCmd) set(opts DeploymentOpts) error {
sess := c.sessionFactory(c.config)
updatedConfig := c.config.SetDeployment(sess.Environment(), opts.Args.NameOrPath)
sess = c.sessionFactory(updatedConfig)
deployment, err := sess.Deployment()
if err != nil {
return err
}
err = updatedConfig.Save()
if err != nil {
return err
}
c.ui.PrintLinef("Deployment set to '%s'", deployment.Name())
_ = DeploymentsTable{[]boshdir.Deployment{deployment}, c.ui}.Print()
return nil
}