Skip to content

Commit 4fdffa3

Browse files
authored
Merge branch 'main' into DEV-2964
2 parents 5a6789e + a6fb9e6 commit 4fdffa3

File tree

90 files changed

+655
-755
lines changed

Some content is hidden

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

90 files changed

+655
-755
lines changed

cmd/atlantis_generate_repo_config.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package cmd
22

33
import (
4-
"github.com/cloudposse/atmos/pkg/schema"
54
"github.com/spf13/cobra"
65

76
e "github.com/cloudposse/atmos/internal/exec"
@@ -23,7 +22,7 @@ var atlantisGenerateRepoConfigCmd = &cobra.Command{
2322
checkAtmosConfig()
2423
err := e.ExecuteAtlantisGenerateRepoConfigCmd(cmd, args)
2524
if err != nil {
26-
u.LogErrorAndExit(schema.AtmosConfiguration{}, err)
25+
u.LogErrorAndExit(err)
2726
}
2827
},
2928
}

cmd/aws_eks_update_kubeconfig.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"github.com/spf13/cobra"
55

66
e "github.com/cloudposse/atmos/internal/exec"
7-
"github.com/cloudposse/atmos/pkg/schema"
87
u "github.com/cloudposse/atmos/pkg/utils"
98
)
109

@@ -36,7 +35,7 @@ See https://docs.aws.amazon.com/cli/latest/reference/eks/update-kubeconfig.html
3635
Run: func(cmd *cobra.Command, args []string) {
3736
err := e.ExecuteAwsEksUpdateKubeconfigCommand(cmd, args)
3837
if err != nil {
39-
u.LogErrorAndExit(schema.AtmosConfiguration{}, err)
38+
u.LogErrorAndExit(err)
4039
}
4140
},
4241
}

cmd/cmd_utils.go

+34-36
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func processCustomCommands(
6262
if _, exist := existingTopLevelCommands[commandConfig.Name]; exist && topLevel {
6363
command = existingTopLevelCommands[commandConfig.Name]
6464
} else {
65-
var customCommand = &cobra.Command{
65+
customCommand := &cobra.Command{
6666
Use: commandConfig.Name,
6767
Short: commandConfig.Description,
6868
Long: commandConfig.Description,
@@ -132,21 +132,21 @@ func processCommandAliases(
132132
aliasCmd := strings.TrimSpace(v)
133133
aliasFor := fmt.Sprintf("alias for '%s'", aliasCmd)
134134

135-
var aliasCommand = &cobra.Command{
135+
aliasCommand := &cobra.Command{
136136
Use: alias,
137137
Short: aliasFor,
138138
Long: aliasFor,
139139
FParseErrWhitelist: struct{ UnknownFlags bool }{UnknownFlags: true},
140140
Run: func(cmd *cobra.Command, args []string) {
141141
err := cmd.ParseFlags(args)
142142
if err != nil {
143-
u.LogErrorAndExit(atmosConfig, err)
143+
u.LogErrorAndExit(err)
144144
}
145145

146146
commandToRun := fmt.Sprintf("%s %s %s", os.Args[0], aliasCmd, strings.Join(args, " "))
147147
err = e.ExecuteShell(atmosConfig, commandToRun, commandToRun, ".", nil, false)
148148
if err != nil {
149-
u.LogErrorAndExit(atmosConfig, err)
149+
u.LogErrorAndExit(err)
150150
}
151151
},
152152
}
@@ -170,7 +170,7 @@ func preCustomCommand(
170170
) {
171171
var sb strings.Builder
172172

173-
//checking for zero arguments in config
173+
// checking for zero arguments in config
174174
if len(commandConfig.Arguments) == 0 {
175175
if len(commandConfig.Steps) > 0 {
176176
// do nothing here; let the code proceed
@@ -182,18 +182,18 @@ func preCustomCommand(
182182
fmt.Sprintf("%d. %s %s %s\n", i+1, parentCommand.Use, commandConfig.Name, c.Name),
183183
)
184184
}
185-
u.LogInfo(schema.AtmosConfiguration{}, sb.String())
185+
u.LogInfo(sb.String())
186186
os.Exit(1)
187187
} else {
188188
// truly invalid, nothing to do
189-
u.LogError(schema.AtmosConfiguration{}, errors.New(
189+
u.LogError(errors.New(
190190
"invalid command: no args, no steps, no sub-commands",
191191
))
192192
os.Exit(1)
193193
}
194194
}
195195

196-
//Check on many arguments required and have no default value
196+
// Check on many arguments required and have no default value
197197
requiredNoDefaultCount := 0
198198
for _, arg := range commandConfig.Arguments {
199199
if arg.Required && arg.Default == "" {
@@ -218,7 +218,7 @@ func preCustomCommand(
218218
if len(args) > 0 {
219219
sb.WriteString(fmt.Sprintf("\nReceived %d argument(s): %s\n", len(args), strings.Join(args, ", ")))
220220
}
221-
u.LogErrorAndExit(schema.AtmosConfiguration{}, errors.New(sb.String()))
221+
u.LogErrorAndExit(errors.New(sb.String()))
222222
}
223223

224224
// Merge user-supplied arguments with defaults
@@ -233,7 +233,7 @@ func preCustomCommand(
233233
} else {
234234
// This theoretically shouldn't happen:
235235
sb.WriteString(fmt.Sprintf("Missing required argument '%s' with no default!\n", arg.Name))
236-
u.LogErrorAndExit(schema.AtmosConfiguration{}, errors.New(sb.String()))
236+
u.LogErrorAndExit(errors.New(sb.String()))
237237
}
238238
}
239239
}
@@ -297,20 +297,20 @@ func executeCustomCommand(
297297
if fl.Type == "" || fl.Type == "string" {
298298
providedFlag, err := flags.GetString(fl.Name)
299299
if err != nil {
300-
u.LogErrorAndExit(atmosConfig, err)
300+
u.LogErrorAndExit(err)
301301
}
302302
flagsData[fl.Name] = providedFlag
303303
} else if fl.Type == "bool" {
304304
boolFlag, err := flags.GetBool(fl.Name)
305305
if err != nil {
306-
u.LogErrorAndExit(atmosConfig, err)
306+
u.LogErrorAndExit(err)
307307
}
308308
flagsData[fl.Name] = boolFlag
309309
}
310310
}
311311

312312
// Prepare template data
313-
var data = map[string]any{
313+
data := map[string]any{
314314
"Arguments": argumentsData,
315315
"Flags": flagsData,
316316
}
@@ -321,27 +321,27 @@ func executeCustomCommand(
321321
// Process Go templates in the command's 'component_config.component'
322322
component, err := e.ProcessTmpl(fmt.Sprintf("component-config-component-%d", i), commandConfig.ComponentConfig.Component, data, false)
323323
if err != nil {
324-
u.LogErrorAndExit(atmosConfig, err)
324+
u.LogErrorAndExit(err)
325325
}
326326
if component == "" || component == "<no value>" {
327-
u.LogErrorAndExit(atmosConfig, fmt.Errorf("the command defines an invalid 'component_config.component: %s' in '%s'",
327+
u.LogErrorAndExit(fmt.Errorf("the command defines an invalid 'component_config.component: %s' in '%s'",
328328
commandConfig.ComponentConfig.Component, cfg.CliConfigFileName+u.DefaultStackConfigFileExtension))
329329
}
330330

331331
// Process Go templates in the command's 'component_config.stack'
332332
stack, err := e.ProcessTmpl(fmt.Sprintf("component-config-stack-%d", i), commandConfig.ComponentConfig.Stack, data, false)
333333
if err != nil {
334-
u.LogErrorAndExit(atmosConfig, err)
334+
u.LogErrorAndExit(err)
335335
}
336336
if stack == "" || stack == "<no value>" {
337-
u.LogErrorAndExit(atmosConfig, fmt.Errorf("the command defines an invalid 'component_config.stack: %s' in '%s'",
337+
u.LogErrorAndExit(fmt.Errorf("the command defines an invalid 'component_config.stack: %s' in '%s'",
338338
commandConfig.ComponentConfig.Stack, cfg.CliConfigFileName+u.DefaultStackConfigFileExtension))
339339
}
340340

341341
// Get the config for the component in the stack
342342
componentConfig, err := e.ExecuteDescribeComponent(component, stack, true)
343343
if err != nil {
344-
u.LogErrorAndExit(atmosConfig, err)
344+
u.LogErrorAndExit(err)
345345
}
346346
data["ComponentConfig"] = componentConfig
347347
}
@@ -358,51 +358,51 @@ func executeCustomCommand(
358358
err = fmt.Errorf("either 'value' or 'valueCommand' can be specified for the ENV var, but not both.\n"+
359359
"Custom command '%s %s' defines 'value=%s' and 'valueCommand=%s' for the ENV var '%s'",
360360
parentCommand.Name(), commandConfig.Name, value, valCommand, key)
361-
u.LogErrorAndExit(atmosConfig, err)
361+
u.LogErrorAndExit(err)
362362
}
363363

364364
// If the command to get the value for the ENV var is provided, execute it
365365
if valCommand != "" {
366366
valCommandName := fmt.Sprintf("env-var-%s-valcommand", key)
367367
res, err := e.ExecuteShellAndReturnOutput(atmosConfig, valCommand, valCommandName, ".", nil, false)
368368
if err != nil {
369-
u.LogErrorAndExit(atmosConfig, err)
369+
u.LogErrorAndExit(err)
370370
}
371371
value = strings.TrimRight(res, "\r\n")
372372
} else {
373373
// Process Go templates in the values of the command's ENV vars
374374
value, err = e.ProcessTmpl(fmt.Sprintf("env-var-%d", i), value, data, false)
375375
if err != nil {
376-
u.LogErrorAndExit(atmosConfig, err)
376+
u.LogErrorAndExit(err)
377377
}
378378
}
379379

380380
envVarsList = append(envVarsList, fmt.Sprintf("%s=%s", key, value))
381381
err = os.Setenv(key, value)
382382
if err != nil {
383-
u.LogErrorAndExit(atmosConfig, err)
383+
u.LogErrorAndExit(err)
384384
}
385385
}
386386

387387
if len(envVarsList) > 0 && commandConfig.Verbose {
388-
u.LogDebug(atmosConfig, "\nUsing ENV vars:")
388+
u.LogDebug("\nUsing ENV vars:")
389389
for _, v := range envVarsList {
390-
u.LogDebug(atmosConfig, v)
390+
u.LogDebug(v)
391391
}
392392
}
393393

394394
// Process Go templates in the command's steps.
395395
// Steps support Go templates and have access to {{ .ComponentConfig.xxx.yyy.zzz }} Go template variables
396396
commandToRun, err := e.ProcessTmpl(fmt.Sprintf("step-%d", i), step, data, false)
397397
if err != nil {
398-
u.LogErrorAndExit(atmosConfig, err)
398+
u.LogErrorAndExit(err)
399399
}
400400

401401
// Execute the command step
402402
commandName := fmt.Sprintf("%s-step-%d", commandConfig.Name, i)
403403
err = e.ExecuteShell(atmosConfig, commandToRun, commandName, ".", envVarsList, false)
404404
if err != nil {
405-
u.LogErrorAndExit(atmosConfig, err)
405+
u.LogErrorAndExit(err)
406406
}
407407
}
408408
}
@@ -435,7 +435,7 @@ func checkAtmosConfig(opts ...AtmosValidateOption) {
435435

436436
atmosConfig, err := cfg.InitCliConfig(schema.ConfigAndStacksInfo{}, false)
437437
if err != nil {
438-
u.LogErrorAndExit(atmosConfig, err)
438+
u.LogErrorAndExit(err)
439439
}
440440

441441
if vCfg.CheckStack {
@@ -455,7 +455,7 @@ func printMessageForMissingAtmosConfig(atmosConfig schema.AtmosConfiguration) {
455455
fmt.Println()
456456
err := tuiUtils.PrintStyledText("ATMOS")
457457
if err != nil {
458-
u.LogErrorAndExit(atmosConfig, err)
458+
u.LogErrorAndExit(err)
459459
}
460460

461461
if atmosConfig.Default {
@@ -501,7 +501,7 @@ func CheckForAtmosUpdateAndPrintMessage(atmosConfig schema.AtmosConfiguration) {
501501
// Load the cache
502502
cacheCfg, err := cfg.LoadCache()
503503
if err != nil {
504-
u.LogWarning(atmosConfig, fmt.Sprintf("Could not load cache: %s", err))
504+
u.LogWarning(fmt.Sprintf("Could not load cache: %s", err))
505505
return
506506
}
507507

@@ -514,12 +514,12 @@ func CheckForAtmosUpdateAndPrintMessage(atmosConfig schema.AtmosConfiguration) {
514514
// Get the latest Atmos release from GitHub
515515
latestReleaseTag, err := u.GetLatestGitHubRepoRelease("cloudposse", "atmos")
516516
if err != nil {
517-
u.LogWarning(atmosConfig, fmt.Sprintf("Failed to retrieve latest Atmos release info: %s", err))
517+
u.LogWarning(fmt.Sprintf("Failed to retrieve latest Atmos release info: %s", err))
518518
return
519519
}
520520

521521
if latestReleaseTag == "" {
522-
u.LogWarning(atmosConfig, "No release information available")
522+
u.LogWarning("No release information available")
523523
return
524524
}
525525

@@ -535,8 +535,7 @@ func CheckForAtmosUpdateAndPrintMessage(atmosConfig schema.AtmosConfiguration) {
535535
// Update the cache to mark the current timestamp
536536
cacheCfg.LastChecked = time.Now().Unix()
537537
if saveErr := cfg.SaveCache(cacheCfg); saveErr != nil {
538-
u.LogWarning(atmosConfig, fmt.Sprintf("Unable to save cache: %s", saveErr))
539-
538+
u.LogWarning(fmt.Sprintf("Unable to save cache: %s", saveErr))
540539
}
541540
}
542541

@@ -554,7 +553,6 @@ func handleHelpRequest(cmd *cobra.Command, args []string) {
554553
}
555554

556555
func showUsageAndExit(cmd *cobra.Command, args []string) {
557-
558556
var suggestions []string
559557
unknownCommand := fmt.Sprintf("Error: Unknown command: %q\n\n", cmd.CommandPath())
560558

@@ -593,7 +591,7 @@ func getConfigAndStacksInfo(commandName string, cmd *cobra.Command, args []strin
593591
checkAtmosConfig()
594592

595593
var argsAfterDoubleDash []string
596-
var finalArgs = args
594+
finalArgs := args
597595

598596
doubleDashIndex := lo.IndexOf(args, "--")
599597
if doubleDashIndex > 0 {
@@ -603,7 +601,7 @@ func getConfigAndStacksInfo(commandName string, cmd *cobra.Command, args []strin
603601

604602
info, err := e.ProcessCommandLineArgs(commandName, cmd, finalArgs, argsAfterDoubleDash)
605603
if err != nil {
606-
u.LogErrorAndExit(schema.AtmosConfiguration{}, err)
604+
u.LogErrorAndExit(err)
607605
}
608606
return info
609607
}

cmd/completion.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func runCompletion(cmd *cobra.Command, args []string) {
3131
}
3232

3333
if err != nil {
34-
u.LogErrorAndExit(atmosConfig, err)
34+
u.LogErrorAndExit(err)
3535
}
3636
}
3737

cmd/describe_affected.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package cmd
22

33
import (
4-
"github.com/cloudposse/atmos/pkg/schema"
54
"github.com/spf13/cobra"
65

76
e "github.com/cloudposse/atmos/internal/exec"
@@ -21,7 +20,7 @@ var describeAffectedCmd = &cobra.Command{
2120

2221
err := e.ExecuteDescribeAffectedCmd(cmd, args)
2322
if err != nil {
24-
u.LogErrorAndExit(schema.AtmosConfiguration{}, err)
23+
u.LogErrorAndExit(err)
2524
}
2625
},
2726
}

cmd/describe_component.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package cmd
22

33
import (
4-
"github.com/cloudposse/atmos/pkg/schema"
54
"github.com/spf13/cobra"
65

76
e "github.com/cloudposse/atmos/internal/exec"
@@ -20,7 +19,7 @@ var describeComponentCmd = &cobra.Command{
2019

2120
err := e.ExecuteDescribeComponentCmd(cmd, args)
2221
if err != nil {
23-
u.LogErrorAndExit(schema.AtmosConfiguration{}, err)
22+
u.LogErrorAndExit(err)
2423
}
2524
},
2625
}
@@ -34,7 +33,7 @@ func init() {
3433

3534
err := describeComponentCmd.MarkPersistentFlagRequired("stack")
3635
if err != nil {
37-
u.LogErrorAndExit(schema.AtmosConfiguration{}, err)
36+
u.LogErrorAndExit(err)
3837
}
3938

4039
describeCmd.AddCommand(describeComponentCmd)

cmd/describe_config.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"github.com/spf13/cobra"
55

66
e "github.com/cloudposse/atmos/internal/exec"
7-
"github.com/cloudposse/atmos/pkg/schema"
87
u "github.com/cloudposse/atmos/pkg/utils"
98
)
109

@@ -16,10 +15,9 @@ var describeConfigCmd = &cobra.Command{
1615
FParseErrWhitelist: struct{ UnknownFlags bool }{UnknownFlags: false},
1716
Args: cobra.NoArgs,
1817
Run: func(cmd *cobra.Command, args []string) {
19-
2018
err := e.ExecuteDescribeConfigCmd(cmd, args)
2119
if err != nil {
22-
u.LogErrorAndExit(schema.AtmosConfiguration{}, err)
20+
u.LogErrorAndExit(err)
2321
}
2422
},
2523
}

0 commit comments

Comments
 (0)