Skip to content

Commit 7a4abbc

Browse files
authored
Update atmos describe affected and atmos describe dependents commands (#1414)
* updates * updates * updates * updates * updates * updates * updates * updates * updates * updates * updates * updates * updates * updates * updates * updates * updates * updates * updates * updates * updates * updates * updates * updates * updates * updates * updates * updates * updates * updates * updates * updates * updates * updates * updates * updates * updates * updates
1 parent ba8288a commit 7a4abbc

File tree

58 files changed

+1669
-236
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1669
-236
lines changed

cmd/cmd_flag_utils.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package cmd
2+
3+
import "github.com/spf13/pflag"
4+
5+
func setStringFlagIfChanged(flags *pflag.FlagSet, name string, target *string) error {
6+
if flags.Changed(name) {
7+
val, err := flags.GetString(name)
8+
if err != nil {
9+
return err
10+
}
11+
*target = val
12+
}
13+
return nil
14+
}
15+
16+
func setBoolFlagIfChanged(flags *pflag.FlagSet, name string, target *bool) error {
17+
if flags.Changed(name) {
18+
val, err := flags.GetBool(name)
19+
if err != nil {
20+
return err
21+
}
22+
*target = val
23+
}
24+
return nil
25+
}
26+
27+
func setSliceOfStringsFlagIfChanged(flags *pflag.FlagSet, name string, target *[]string) error {
28+
if flags.Changed(name) {
29+
val, err := flags.GetStringSlice(name)
30+
if err != nil {
31+
return err
32+
}
33+
*target = val
34+
}
35+
return nil
36+
}

cmd/describe_affected.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ func init() {
4141
describeAffectedCmd.PersistentFlags().Bool("process-functions", true, "Enable/disable YAML functions processing in Atmos stack manifests when executing the command")
4242
describeAffectedCmd.PersistentFlags().StringSlice("skip", nil, "Skip executing a YAML function when processing Atmos stack manifests")
4343
describeAffectedCmd.PersistentFlags().Bool("verbose", false, "Deprecated. Alias for `--logs-level=Debug`")
44+
describeAffectedCmd.PersistentFlags().Bool("exclude-locked", false, "Exclude the locked components (`metadata.locked: true`) from the output")
4445

4546
describeCmd.AddCommand(describeAffectedCmd)
4647
}

cmd/describe_affected_test.go

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,12 @@ func TestSetFlagValueInCliArgs(t *testing.T) {
4343
fs.Set("format", "yaml")
4444
},
4545
expected: &exec.DescribeAffectedCmdArgs{
46-
Ref: "main",
47-
SHA: "abc123",
48-
IncludeDependents: true,
49-
Format: "yaml",
46+
Ref: "main",
47+
SHA: "abc123",
48+
IncludeDependents: true,
49+
Format: "yaml",
50+
ProcessTemplates: true,
51+
ProcessYamlFunctions: true,
5052
},
5153
},
5254
{
@@ -55,10 +57,12 @@ func TestSetFlagValueInCliArgs(t *testing.T) {
5557
fs.Set("upload", "true")
5658
},
5759
expected: &exec.DescribeAffectedCmdArgs{
58-
Upload: true,
59-
IncludeDependents: true,
60-
IncludeSettings: true,
61-
Format: "json",
60+
Upload: true,
61+
IncludeDependents: true,
62+
IncludeSettings: true,
63+
Format: "json",
64+
ProcessTemplates: true,
65+
ProcessYamlFunctions: true,
6266
},
6367
},
6468
{
@@ -67,7 +71,9 @@ func TestSetFlagValueInCliArgs(t *testing.T) {
6771
// No flags set
6872
},
6973
expected: &exec.DescribeAffectedCmdArgs{
70-
Format: "json",
74+
Format: "json",
75+
ProcessTemplates: true,
76+
ProcessYamlFunctions: true,
7177
},
7278
},
7379
{
@@ -76,7 +82,9 @@ func TestSetFlagValueInCliArgs(t *testing.T) {
7682
fs.Set("format", "json")
7783
},
7884
expected: &exec.DescribeAffectedCmdArgs{
79-
Format: "json",
85+
Format: "json",
86+
ProcessTemplates: true,
87+
ProcessYamlFunctions: true,
8088
},
8189
},
8290
}

cmd/describe_dependents.go

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,24 +72,49 @@ func setFlagsForDescribeDependentsCmd(flags *pflag.FlagSet, describe *exec.Descr
7272
if err != nil {
7373
return err
7474
}
75+
7576
err = setStringFlagIfChanged(flags, "file", &describe.File)
7677
if err != nil {
7778
return err
7879
}
80+
7981
err = setStringFlagIfChanged(flags, "stack", &describe.Stack)
8082
if err != nil {
8183
return err
8284
}
85+
8386
err = setStringFlagIfChanged(flags, "query", &describe.Query)
8487
if err != nil {
8588
return err
8689
}
90+
91+
// `true` by default
92+
describe.ProcessTemplates = true
93+
err = setBoolFlagIfChanged(flags, "process-templates", &describe.ProcessTemplates)
94+
if err != nil {
95+
return err
96+
}
97+
98+
// `true` by default
99+
describe.ProcessYamlFunctions = true
100+
err = setBoolFlagIfChanged(flags, "process-functions", &describe.ProcessYamlFunctions)
101+
if err != nil {
102+
return err
103+
}
104+
105+
err = setSliceOfStringsFlagIfChanged(flags, "skip", &describe.Skip)
106+
if err != nil {
107+
return err
108+
}
109+
87110
if describe.Format == "" {
88111
describe.Format = "json"
89112
}
113+
90114
if describe.Format != "json" && describe.Format != "yaml" {
91115
return ErrInvalidFormat
92116
}
117+
93118
return nil
94119
}
95120

@@ -99,7 +124,10 @@ func init() {
99124
AddStackCompletion(describeDependentsCmd)
100125
describeDependentsCmd.PersistentFlags().StringP("format", "f", "json", "The output format (`json` is default)")
101126
describeDependentsCmd.PersistentFlags().String("file", "", "Write the result to the file")
102-
describeDependentsCmd.PersistentFlags().String("query", "", "Filter the output using a JMESPath query")
127+
describeDependentsCmd.PersistentFlags().StringP("query", "q", "", "Filter the output using a YQ expression")
128+
describeDependentsCmd.PersistentFlags().Bool("process-templates", true, "Enable/disable Go template processing in Atmos stack manifests when executing the command")
129+
describeDependentsCmd.PersistentFlags().Bool("process-functions", true, "Enable/disable YAML functions processing in Atmos stack manifests when executing the command")
130+
describeDependentsCmd.PersistentFlags().StringSlice("skip", nil, "Skip executing a YAML function when processing Atmos stack manifests")
103131

104132
err := describeDependentsCmd.MarkPersistentFlagRequired("stack")
105133
errUtils.CheckErrorPrintAndExit(err, "", "")

cmd/describe_dependents_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ func TestSetFlagInDescribeDependents(t *testing.T) {
4444
fs.Set("format", "yaml")
4545
},
4646
expected: &exec.DescribeDependentsExecProps{
47-
Format: "yaml",
47+
Format: "yaml",
48+
ProcessTemplates: true,
49+
ProcessYamlFunctions: true,
4850
},
4951
},
5052
{
@@ -53,7 +55,9 @@ func TestSetFlagInDescribeDependents(t *testing.T) {
5355
// No flags set
5456
},
5557
expected: &exec.DescribeDependentsExecProps{
56-
Format: "json",
58+
Format: "json",
59+
ProcessTemplates: true,
60+
ProcessYamlFunctions: true,
5761
},
5862
},
5963
{

cmd/describe_workflows.go

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ import (
1111
"github.com/cloudposse/atmos/pkg/schema"
1212
)
1313

14-
// describeWorkflowsCmd executes 'atmos describe workflows' CLI commands
14+
var (
15+
ErrInvalidOutputType = fmt.Errorf("invalid output type specified. Valid values are 'list', 'map', and 'all'")
16+
ErrInvalidFormat = fmt.Errorf("invalid format specified. Valid values are 'yaml' and 'json'")
17+
)
18+
19+
// describeWorkflowsCmd executes 'atmos describe workflows' CLI commands.
1520
var describeWorkflowsCmd = &cobra.Command{
1621
Use: "workflows",
1722
Short: "List Atmos workflows and their associated files",
@@ -83,22 +88,6 @@ func flagsToDescribeWorkflowsArgs(flags *pflag.FlagSet, describe *exec.DescribeW
8388
return nil
8489
}
8590

86-
func setStringFlagIfChanged(flags *pflag.FlagSet, name string, target *string) error {
87-
if flags.Changed(name) {
88-
val, err := flags.GetString(name)
89-
if err != nil {
90-
return err
91-
}
92-
*target = val
93-
}
94-
return nil
95-
}
96-
97-
var (
98-
ErrInvalidOutputType = fmt.Errorf("invalid output type specified. Valid values are 'list', 'map', and 'all'")
99-
ErrInvalidFormat = fmt.Errorf("invalid format specified. Valid values are 'yaml' and 'json'")
100-
)
101-
10291
func validateAndSetDefaults(describe *exec.DescribeWorkflowsArgs) error {
10392
if describe.Format == "" {
10493
describe.Format = "yaml"

examples/demo-context/schemas/atmos-manifest.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,9 @@
916916
{
917917
"type": "object",
918918
"properties": {
919+
"stack": {
920+
"type": "string"
921+
},
919922
"namespace": {
920923
"type": "string"
921924
},

examples/demo-helmfile/schemas/atmos-manifest.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,9 @@
916916
{
917917
"type": "object",
918918
"properties": {
919+
"stack": {
920+
"type": "string"
921+
},
919922
"namespace": {
920923
"type": "string"
921924
},

examples/demo-localstack/schemas/atmos-manifest.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,9 @@
916916
{
917917
"type": "object",
918918
"properties": {
919+
"stack": {
920+
"type": "string"
921+
},
919922
"namespace": {
920923
"type": "string"
921924
},

examples/quick-start-advanced/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ ARG GEODESIC_OS=debian
66
# https://atmos.tools/
77
# https://github.com/cloudposse/atmos
88
# https://github.com/cloudposse/atmos/releases
9-
ARG ATMOS_VERSION=1.187.0
9+
ARG ATMOS_VERSION=1.188.0
1010

1111
# Terraform: https://github.com/hashicorp/terraform/releases
1212
ARG TF_VERSION=1.5.7

0 commit comments

Comments
 (0)