Skip to content

Commit

Permalink
error checking on retreiving context
Browse files Browse the repository at this point in the history
  • Loading branch information
mcalhoun committed Dec 16, 2024
1 parent 1d23a43 commit 8a7e36c
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 5 deletions.
7 changes: 6 additions & 1 deletion cmd/cmd_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,12 @@ func CheckForAtmosUpdateAndPrintMessage(cliConfig schema.CliConfiguration) {
}

func customHelpMessageToUpgradeToAtmosLatestRelease(cmd *cobra.Command, args []string) {
atmosConfig := cmd.Context().Value(contextKey("atmos_config")).(*schema.CliConfiguration)
value := cmd.Context().Value(contextKey("atmos_config"))
if value == nil {
u.LogErrorAndExit(schema.CliConfiguration{}, fmt.Errorf("atmos configuration not found in context"))
}
atmosConfig := value.(*schema.CliConfiguration)

originalHelpFunc(cmd, args)
CheckForAtmosUpdateAndPrintMessage(*atmosConfig)
}
Expand Down
9 changes: 8 additions & 1 deletion cmd/helmfile.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package cmd

import (
"fmt"

"github.com/samber/lo"
"github.com/spf13/cobra"

Expand Down Expand Up @@ -34,7 +36,12 @@ var helmfileCmd = &cobra.Command{
// Exit on help
if info.NeedHelp {
// Check for the latest Atmos release on GitHub and print update message
atmosConfig := cmd.Context().Value(contextKey("atmos_config")).(*schema.CliConfiguration)
value := cmd.Context().Value(contextKey("atmos_config"))
if value == nil {
u.LogErrorAndExit(schema.CliConfiguration{}, fmt.Errorf("atmos configuration not found in context"))
}
atmosConfig := value.(*schema.CliConfiguration)

CheckForAtmosUpdateAndPrintMessage(*atmosConfig)
return
}
Expand Down
9 changes: 8 additions & 1 deletion cmd/terraform.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package cmd

import (
"fmt"

"github.com/samber/lo"
"github.com/spf13/cobra"

Expand Down Expand Up @@ -34,7 +36,12 @@ var terraformCmd = &cobra.Command{
// Exit on help
if info.NeedHelp {
// Check for the latest Atmos release on GitHub and print update message
atmosConfig := cmd.Context().Value(contextKey("atmos_config")).(*schema.CliConfiguration)
value := cmd.Context().Value(contextKey("atmos_config"))
if value == nil {
u.LogErrorAndExit(schema.CliConfiguration{}, fmt.Errorf("atmos configuration not found in context"))
}
atmosConfig := value.(*schema.CliConfiguration)

CheckForAtmosUpdateAndPrintMessage(*atmosConfig)
return
}
Expand Down
8 changes: 7 additions & 1 deletion cmd/vendor_pull.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package cmd

import (
"fmt"

"github.com/spf13/cobra"

e "github.com/cloudposse/atmos/internal/exec"
Expand All @@ -15,7 +17,11 @@ var vendorPullCmd = &cobra.Command{
Long: `This command executes 'atmos vendor pull' CLI commands`,
FParseErrWhitelist: struct{ UnknownFlags bool }{UnknownFlags: false},
Run: func(cmd *cobra.Command, args []string) {
atmosConfig := cmd.Context().Value(contextKey("atmos_config")).(*schema.CliConfiguration)
value := cmd.Context().Value(contextKey("atmos_config"))
if value == nil {
u.LogErrorAndExit(schema.CliConfiguration{}, fmt.Errorf("atmos configuration not found in context"))
}
atmosConfig := value.(*schema.CliConfiguration)

// WithStackValidation is a functional option that enables/disables stack configuration validation
// based on whether the --stack flag is provided
Expand Down
6 changes: 5 additions & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ var versionCmd = &cobra.Command{
}

// Check for the cache and print update message
atmosConfig := cmd.Context().Value(contextKey("atmos_config")).(*schema.CliConfiguration)
value := cmd.Context().Value(contextKey("atmos_config"))
if value == nil {
u.LogErrorAndExit(schema.CliConfiguration{}, fmt.Errorf("atmos configuration not found in context"))
}
atmosConfig := value.(*schema.CliConfiguration)
CheckForAtmosUpdateAndPrintMessage(*atmosConfig)
},
}
Expand Down

0 comments on commit 8a7e36c

Please sign in to comment.