forked from cloudfoundry/bosh-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
alias_env.go
49 lines (38 loc) · 900 Bytes
/
alias_env.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
package cmd
import (
cmdconf "github.com/cloudfoundry/bosh-cli/cmd/config"
boshui "github.com/cloudfoundry/bosh-cli/ui"
)
type AliasEnvCmd struct {
sessionFactory func(cmdconf.Config) Session
config cmdconf.Config
ui boshui.UI
}
func NewAliasEnvCmd(
sessionFactory func(cmdconf.Config) Session,
config cmdconf.Config,
ui boshui.UI,
) AliasEnvCmd {
return AliasEnvCmd{sessionFactory: sessionFactory, config: config, ui: ui}
}
func (c AliasEnvCmd) Run(opts AliasEnvOpts) error {
updatedConfig, err := c.config.AliasEnvironment(opts.URL, opts.Args.Alias, opts.CACert)
if err != nil {
return err
}
sess := c.sessionFactory(updatedConfig)
director, err := sess.Director()
if err != nil {
return err
}
info, err := director.Info()
if err != nil {
return err
}
err = updatedConfig.Save()
if err != nil {
return err
}
InfoTable{info, c.ui}.Print()
return nil
}