-
-
Notifications
You must be signed in to change notification settings - Fork 82
/
describe_component.go
76 lines (60 loc) 路 1.72 KB
/
describe_component.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
package exec
import (
"github.com/pkg/errors"
"github.com/spf13/cobra"
cfg "github.com/cloudposse/atmos/pkg/config"
"github.com/cloudposse/atmos/pkg/schema"
)
// ExecuteDescribeComponentCmd executes `describe component` command
func ExecuteDescribeComponentCmd(cmd *cobra.Command, args []string) error {
if len(args) != 1 {
return errors.New("invalid arguments. The command requires one argument `component`")
}
_, err := cfg.InitCliConfig(schema.ConfigAndStacksInfo{}, true)
if err != nil {
return err
}
flags := cmd.Flags()
stack, err := flags.GetString("stack")
if err != nil {
return err
}
format, err := flags.GetString("format")
if err != nil {
return err
}
file, err := flags.GetString("file")
if err != nil {
return err
}
component := args[0]
componentSection, err := ExecuteDescribeComponent(component, stack)
if err != nil {
return err
}
err = printOrWriteToFile(format, file, componentSection)
if err != nil {
return err
}
return nil
}
// ExecuteDescribeComponent describes component config
func ExecuteDescribeComponent(component string, stack string) (map[string]any, error) {
var configAndStacksInfo schema.ConfigAndStacksInfo
configAndStacksInfo.ComponentFromArg = component
configAndStacksInfo.Stack = stack
cliConfig, err := cfg.InitCliConfig(configAndStacksInfo, true)
if err != nil {
return nil, err
}
configAndStacksInfo.ComponentType = "terraform"
configAndStacksInfo, err = ProcessStacks(cliConfig, configAndStacksInfo, true)
if err != nil {
configAndStacksInfo.ComponentType = "helmfile"
configAndStacksInfo, err = ProcessStacks(cliConfig, configAndStacksInfo, true)
if err != nil {
return nil, err
}
}
return configAndStacksInfo.ComponentSection, nil
}