Skip to content

Commit

Permalink
dev-2668: migrate to charmbracelet logger
Browse files Browse the repository at this point in the history
  • Loading branch information
mcalhoun committed Jan 28, 2025
1 parent 83bd190 commit d62491c
Show file tree
Hide file tree
Showing 74 changed files with 729 additions and 529 deletions.
3 changes: 1 addition & 2 deletions cmd/atlantis_generate_repo_config.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cmd

import (
"github.com/cloudposse/atmos/pkg/schema"
"github.com/spf13/cobra"

e "github.com/cloudposse/atmos/internal/exec"
Expand All @@ -20,7 +19,7 @@ var atlantisGenerateRepoConfigCmd = &cobra.Command{

err := e.ExecuteAtlantisGenerateRepoConfigCmd(cmd, args)
if err != nil {
u.LogErrorAndExit(schema.AtmosConfiguration{}, err)
u.LogErrorAndExit(err)
}
},
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/aws_eks_update_kubeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"github.com/spf13/cobra"

e "github.com/cloudposse/atmos/internal/exec"
"github.com/cloudposse/atmos/pkg/schema"
u "github.com/cloudposse/atmos/pkg/utils"
)

Expand Down Expand Up @@ -36,7 +35,7 @@ See https://docs.aws.amazon.com/cli/latest/reference/eks/update-kubeconfig.html
Run: func(cmd *cobra.Command, args []string) {
err := e.ExecuteAwsEksUpdateKubeconfigCommand(cmd, args)
if err != nil {
u.LogErrorAndExit(schema.AtmosConfiguration{}, err)
u.LogErrorAndExit(err)
}
},
}
Expand Down
54 changes: 27 additions & 27 deletions cmd/cmd_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,13 @@ func processCommandAliases(
Run: func(cmd *cobra.Command, args []string) {
err := cmd.ParseFlags(args)
if err != nil {
u.LogErrorAndExit(atmosConfig, err)
u.LogErrorAndExit(err)
}

commandToRun := fmt.Sprintf("%s %s %s", os.Args[0], aliasCmd, strings.Join(args, " "))
err = e.ExecuteShell(atmosConfig, commandToRun, commandToRun, ".", nil, false)
if err != nil {
u.LogErrorAndExit(atmosConfig, err)
u.LogErrorAndExit(err)
}
},
}
Expand Down Expand Up @@ -181,11 +181,11 @@ func preCustomCommand(
fmt.Sprintf("%d. %s %s %s\n", i+1, parentCommand.Use, commandConfig.Name, c.Name),
)
}
u.LogInfo(schema.AtmosConfiguration{}, sb.String())
u.LogInfo(sb.String())
os.Exit(1)
} else {
// truly invalid, nothing to do
u.LogError(schema.AtmosConfiguration{}, errors.New(
u.LogError(errors.New(
"invalid command: no args, no steps, no sub-commands",
))
os.Exit(1)
Expand Down Expand Up @@ -217,7 +217,7 @@ func preCustomCommand(
if len(args) > 0 {
sb.WriteString(fmt.Sprintf("\nReceived %d argument(s): %s\n", len(args), strings.Join(args, ", ")))
}
u.LogErrorAndExit(schema.AtmosConfiguration{}, errors.New(sb.String()))
u.LogErrorAndExit(errors.New(sb.String()))
}

// Merge user-supplied arguments with defaults
Expand All @@ -232,7 +232,7 @@ func preCustomCommand(
} else {
// This theoretically shouldn't happen:
sb.WriteString(fmt.Sprintf("Missing required argument '%s' with no default!\n", arg.Name))
u.LogErrorAndExit(schema.AtmosConfiguration{}, errors.New(sb.String()))
u.LogErrorAndExit(errors.New(sb.String()))
}
}
}
Expand Down Expand Up @@ -296,13 +296,13 @@ func executeCustomCommand(
if fl.Type == "" || fl.Type == "string" {
providedFlag, err := flags.GetString(fl.Name)
if err != nil {
u.LogErrorAndExit(atmosConfig, err)
u.LogErrorAndExit(err)
}
flagsData[fl.Name] = providedFlag
} else if fl.Type == "bool" {
boolFlag, err := flags.GetBool(fl.Name)
if err != nil {
u.LogErrorAndExit(atmosConfig, err)
u.LogErrorAndExit(err)
}
flagsData[fl.Name] = boolFlag
}
Expand All @@ -320,27 +320,27 @@ func executeCustomCommand(
// Process Go templates in the command's 'component_config.component'
component, err := e.ProcessTmpl(fmt.Sprintf("component-config-component-%d", i), commandConfig.ComponentConfig.Component, data, false)
if err != nil {
u.LogErrorAndExit(atmosConfig, err)
u.LogErrorAndExit(err)
}
if component == "" || component == "<no value>" {
u.LogErrorAndExit(atmosConfig, fmt.Errorf("the command defines an invalid 'component_config.component: %s' in '%s'",
u.LogErrorAndExit(fmt.Errorf("the command defines an invalid 'component_config.component: %s' in '%s'",
commandConfig.ComponentConfig.Component, cfg.CliConfigFileName+u.DefaultStackConfigFileExtension))
}

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

// Get the config for the component in the stack
componentConfig, err := e.ExecuteDescribeComponent(component, stack, true)
if err != nil {
u.LogErrorAndExit(atmosConfig, err)
u.LogErrorAndExit(err)
}
data["ComponentConfig"] = componentConfig
}
Expand All @@ -357,51 +357,51 @@ func executeCustomCommand(
err = fmt.Errorf("either 'value' or 'valueCommand' can be specified for the ENV var, but not both.\n"+
"Custom command '%s %s' defines 'value=%s' and 'valueCommand=%s' for the ENV var '%s'",
parentCommand.Name(), commandConfig.Name, value, valCommand, key)
u.LogErrorAndExit(atmosConfig, err)
u.LogErrorAndExit(err)
}

// If the command to get the value for the ENV var is provided, execute it
if valCommand != "" {
valCommandName := fmt.Sprintf("env-var-%s-valcommand", key)
res, err := e.ExecuteShellAndReturnOutput(atmosConfig, valCommand, valCommandName, ".", nil, false)
if err != nil {
u.LogErrorAndExit(atmosConfig, err)
u.LogErrorAndExit(err)
}
value = strings.TrimRight(res, "\r\n")
} else {
// Process Go templates in the values of the command's ENV vars
value, err = e.ProcessTmpl(fmt.Sprintf("env-var-%d", i), value, data, false)
if err != nil {
u.LogErrorAndExit(atmosConfig, err)
u.LogErrorAndExit(err)
}
}

envVarsList = append(envVarsList, fmt.Sprintf("%s=%s", key, value))
err = os.Setenv(key, value)
if err != nil {
u.LogErrorAndExit(atmosConfig, err)
u.LogErrorAndExit(err)
}
}

if len(envVarsList) > 0 && commandConfig.Verbose {
u.LogDebug(atmosConfig, "\nUsing ENV vars:")
u.LogDebug("\nUsing ENV vars:")
for _, v := range envVarsList {
u.LogDebug(atmosConfig, v)
u.LogDebug(v)
}
}

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

// Execute the command step
commandName := fmt.Sprintf("%s-step-%d", commandConfig.Name, i)
err = e.ExecuteShell(atmosConfig, commandToRun, commandName, ".", envVarsList, false)
if err != nil {
u.LogErrorAndExit(atmosConfig, err)
u.LogErrorAndExit(err)
}
}
}
Expand Down Expand Up @@ -434,7 +434,7 @@ func checkAtmosConfig(opts ...AtmosValidateOption) {

atmosConfig, err := cfg.InitCliConfig(schema.ConfigAndStacksInfo{}, false)
if err != nil {
u.LogErrorAndExit(atmosConfig, err)
u.LogErrorAndExit(err)
}

if vCfg.CheckStack {
Expand All @@ -454,7 +454,7 @@ func printMessageForMissingAtmosConfig(atmosConfig schema.AtmosConfiguration) {
fmt.Println()
err := tuiUtils.PrintStyledText("ATMOS")
if err != nil {
u.LogErrorAndExit(atmosConfig, err)
u.LogErrorAndExit(err)
}

if atmosConfig.Default {
Expand Down Expand Up @@ -500,7 +500,7 @@ func CheckForAtmosUpdateAndPrintMessage(atmosConfig schema.AtmosConfiguration) {
// Load the cache
cacheCfg, err := cfg.LoadCache()
if err != nil {
u.LogWarning(atmosConfig, fmt.Sprintf("Could not load cache: %s", err))
u.LogWarning(fmt.Sprintf("Could not load cache: %s", err))
return
}

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

if latestReleaseTag == "" {
u.LogWarning(atmosConfig, "No release information available")
u.LogWarning("No release information available")
return
}

Expand All @@ -534,7 +534,7 @@ func CheckForAtmosUpdateAndPrintMessage(atmosConfig schema.AtmosConfiguration) {
// Update the cache to mark the current timestamp
cacheCfg.LastChecked = time.Now().Unix()
if saveErr := cfg.SaveCache(cacheCfg); saveErr != nil {
u.LogWarning(atmosConfig, fmt.Sprintf("Unable to save cache: %s", saveErr))
u.LogWarning(fmt.Sprintf("Unable to save cache: %s", saveErr))

}
}
Expand Down
4 changes: 1 addition & 3 deletions cmd/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package cmd
import (
"os"

"github.com/cloudposse/atmos/pkg/schema"

"github.com/spf13/cobra"

u "github.com/cloudposse/atmos/pkg/utils"
Expand Down Expand Up @@ -32,7 +30,7 @@ var completionCmd = &cobra.Command{
}

if err != nil {
u.LogErrorAndExit(schema.AtmosConfiguration{}, err)
u.LogErrorAndExit(err)
}
},
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/describe_affected.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cmd

import (
"github.com/cloudposse/atmos/pkg/schema"
"github.com/spf13/cobra"

e "github.com/cloudposse/atmos/internal/exec"
Expand All @@ -20,7 +19,7 @@ var describeAffectedCmd = &cobra.Command{

err := e.ExecuteDescribeAffectedCmd(cmd, args)
if err != nil {
u.LogErrorAndExit(schema.AtmosConfiguration{}, err)
u.LogErrorAndExit(err)
}
},
}
Expand Down
5 changes: 2 additions & 3 deletions cmd/describe_component.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cmd

import (
"github.com/cloudposse/atmos/pkg/schema"
"github.com/spf13/cobra"

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

err := e.ExecuteDescribeComponentCmd(cmd, args)
if err != nil {
u.LogErrorAndExit(schema.AtmosConfiguration{}, err)
u.LogErrorAndExit(err)
}
},
}
Expand All @@ -34,7 +33,7 @@ func init() {

err := describeComponentCmd.MarkPersistentFlagRequired("stack")
if err != nil {
u.LogErrorAndExit(schema.AtmosConfiguration{}, err)
u.LogErrorAndExit(err)
}

describeCmd.AddCommand(describeComponentCmd)
Expand Down
3 changes: 1 addition & 2 deletions cmd/describe_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"github.com/spf13/cobra"

e "github.com/cloudposse/atmos/internal/exec"
"github.com/cloudposse/atmos/pkg/schema"
u "github.com/cloudposse/atmos/pkg/utils"
)

Expand All @@ -17,7 +16,7 @@ var describeConfigCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
err := e.ExecuteDescribeConfigCmd(cmd, args)
if err != nil {
u.LogErrorAndExit(schema.AtmosConfiguration{}, err)
u.LogErrorAndExit(err)
}
},
}
Expand Down
5 changes: 2 additions & 3 deletions cmd/describe_dependents.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cmd

import (
"github.com/cloudposse/atmos/pkg/schema"
"github.com/spf13/cobra"

e "github.com/cloudposse/atmos/internal/exec"
Expand All @@ -21,7 +20,7 @@ var describeDependentsCmd = &cobra.Command{

err := e.ExecuteDescribeDependentsCmd(cmd, args)
if err != nil {
u.LogErrorAndExit(schema.AtmosConfiguration{}, err)
u.LogErrorAndExit(err)
}
},
}
Expand All @@ -35,7 +34,7 @@ func init() {

err := describeDependentsCmd.MarkPersistentFlagRequired("stack")
if err != nil {
u.LogErrorAndExit(schema.AtmosConfiguration{}, err)
u.LogErrorAndExit(err)
}

describeCmd.AddCommand(describeDependentsCmd)
Expand Down
3 changes: 1 addition & 2 deletions cmd/describe_stacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"github.com/spf13/cobra"

e "github.com/cloudposse/atmos/internal/exec"
"github.com/cloudposse/atmos/pkg/schema"
u "github.com/cloudposse/atmos/pkg/utils"
)

Expand All @@ -20,7 +19,7 @@ var describeStacksCmd = &cobra.Command{

err := e.ExecuteDescribeStacksCmd(cmd, args)
if err != nil {
u.LogErrorAndExit(schema.AtmosConfiguration{}, err)
u.LogErrorAndExit(err)
}
},
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/describe_workflows.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"github.com/spf13/cobra"

e "github.com/cloudposse/atmos/internal/exec"
"github.com/cloudposse/atmos/pkg/schema"
u "github.com/cloudposse/atmos/pkg/utils"
)

Expand All @@ -24,7 +23,7 @@ var describeWorkflowsCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
err := e.ExecuteDescribeWorkflowsCmd(cmd, args)
if err != nil {
u.LogErrorAndExit(schema.AtmosConfiguration{}, err)
u.LogErrorAndExit(err)
}
},
}
Expand Down
Loading

0 comments on commit d62491c

Please sign in to comment.