-
Notifications
You must be signed in to change notification settings - Fork 0
/
storage_plans_cmd.go
51 lines (41 loc) · 1.36 KB
/
storage_plans_cmd.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
// Copyright (c) 2017-2021 Ingram Micro Inc.
package cmd
import (
"github.com/ingrammicro/cio/api/storage"
"github.com/ingrammicro/cio/utils"
"github.com/ingrammicro/cio/utils/format"
"github.com/urfave/cli"
)
// WireUpStoragePlan prepares common resources to send request to Concerto API
func WireUpStoragePlan(c *cli.Context) (ns *storage.StoragePlanService, f format.Formatter) {
f = format.GetFormatter()
config, err := utils.GetConcertoConfig()
if err != nil {
f.PrintFatal("Couldn't wire up config", err)
}
hcs, err := utils.NewHTTPConcertoService(config)
if err != nil {
f.PrintFatal("Couldn't wire up concerto service", err)
}
ns, err = storage.NewStoragePlanService(hcs)
if err != nil {
f.PrintFatal("Couldn't wire up storage plan service", err)
}
return ns, f
}
// StoragePlanShow subcommand function
func StoragePlanShow(c *cli.Context) error {
debugCmdFuncInfo(c)
storagePlanSvc, formatter := WireUpStoragePlan(c)
checkRequiredFlags(c, []string{"id"}, formatter)
storagePlans, err := storagePlanSvc.GetStoragePlan(c.String("id"))
if err != nil {
formatter.PrintFatal("Couldn't receive storage plan data", err)
}
locationsMap := LoadLocationsMapping(c)
storagePlans.LocationName = locationsMap[storagePlans.LocationID]
if err = formatter.PrintItem(*storagePlans); err != nil {
formatter.PrintFatal(PrintFormatError, err)
}
return nil
}