-
Notifications
You must be signed in to change notification settings - Fork 0
/
show.go
81 lines (64 loc) · 1.81 KB
/
show.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
69
70
71
72
73
74
75
76
77
78
79
80
81
package cloud
import (
"fmt"
"github.com/spf13/cobra"
"github.com/mevansam/goforms/forms"
"github.com/mevansam/goforms/ux"
"github.com/appbricks/cloud-builder-cli/config"
"github.com/appbricks/cloud-builder/auth"
cbcli_auth "github.com/appbricks/cloud-builder-cli/auth"
cbcli_utils "github.com/appbricks/cloud-builder-cli/utils"
)
var showCommand = &cobra.Command{
Use: "show [name]",
Short: "Show information regarding a particular cloud.",
Long: `
Show detailed information regarding the given cloud. This sub-command
will also show help for the configuration data required for the given
cloud.
`,
PreRun: cbcli_auth.AssertAuthorized(auth.NewRoleMask(auth.Admin), nil),
Run: func(cmd *cobra.Command, args []string) {
ShowCloud(args[0])
},
Args: cobra.ExactArgs(1),
}
func ShowCloud(name string) {
var (
err error
inputForm forms.InputForm
textForm *ux.TextForm
)
if provider, err := config.Config.TargetContext().GetCloudProvider(name); err == nil && provider != nil {
if inputForm, err = provider.InputForm(); err != nil {
cbcli_utils.ShowErrorAndExit(err.Error())
}
fmt.Printf("\n")
if textForm, err = ux.NewTextForm(
"Cloud Provider Configuration",
"CONFIGURATION DATA INPUT REFERENCE",
inputForm); err != nil {
// if this happens there is an internal
// error and it is most likely a bug
cbcli_utils.ShowErrorAndExit(err.Error())
}
textForm.ShowInputReference(ux.DescAndDefaults, 0, 2, 80)
fmt.Print("\n\n")
return
}
if err != nil {
cbcli_utils.ShowErrorAndExit(err.Error())
} else {
cbcli_utils.ShowErrorAndExit(
fmt.Sprintf(
"Unknown cloud IaaS name \"%s\" given to the show command. "+
"Run 'cb cloud list' to get list of available clouds.",
name,
),
)
}
}
func init() {
flags := showCommand.Flags()
flags.SortFlags = false
}