-
Notifications
You must be signed in to change notification settings - Fork 162
/
config.go
49 lines (37 loc) · 1.21 KB
/
config.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 (
. "github.com/cloudfoundry/bosh-cli/cmd/opts"
boshdir "github.com/cloudfoundry/bosh-cli/director"
boshui "github.com/cloudfoundry/bosh-cli/ui"
bosherr "github.com/cloudfoundry/bosh-utils/errors"
)
type ConfigCmd struct {
ui boshui.UI
director boshdir.Director
}
func NewConfigCmd(ui boshui.UI, director boshdir.Director) ConfigCmd {
return ConfigCmd{ui: ui, director: director}
}
func (c ConfigCmd) Run(opts ConfigOpts) error {
if opts == (ConfigOpts{}) {
return bosherr.Error("Either <ID> or parameters --type and --name must be provided")
}
if opts.Args.ID != "" && (opts.Type != "" || opts.Name != "") {
return bosherr.Error("Can only specify one of ID or parameters '--type' and '--name'")
}
if (opts.Args.ID == "" && opts.Type != "" && opts.Name == "") || (opts.Args.ID == "" && opts.Name != "" && opts.Type == "") {
return bosherr.Error("Need to specify both parameters '--type' and '--name'")
}
var config boshdir.Config
var err error
if opts.Args.ID != "" {
config, err = c.director.LatestConfigByID(opts.Args.ID)
} else {
config, err = c.director.LatestConfig(opts.Type, opts.Name)
}
if err != nil {
return err
}
ConfigTable{config, c.ui}.Print()
return nil
}