Skip to content

Commit 247ab4c

Browse files
committed
fix golang lint
1 parent 95a14e8 commit 247ab4c

File tree

5 files changed

+38
-32
lines changed

5 files changed

+38
-32
lines changed

cmd/root.go

-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ func init() {
196196
Key: "logs.level",
197197
DefaultValue: "Info",
198198
})
199-
// RootCmd.PersistentFlags().String("logs-level", "Info", "Logs level. Supported log levels are Trace, Debug, Info, Warning, Off. If the log level is set to Off, Atmos will not log any messages")
200199
config.DefaultConfigHandler.AddConfig(RootCmd, cfg.ConfigOptions{
201200
FlagName: "logs-file",
202201
DefaultValue: "/dev/stderr",

cmd/terraform.go

+23-11
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ func init() {
3636
}
3737

3838
func addTerraformCommandConfig() {
39+
addTerraformCommandSettings()
40+
addTerraformInitSettings()
41+
addTerraformExecutionSettings()
42+
}
43+
44+
func addTerraformCommandSettings() {
3945
config.DefaultConfigHandler.AddConfig(terraformCmd, cfg.ConfigOptions{
4046
FlagName: "terraform-command",
4147
EnvVar: "ATMOS_COMPONENTS_TERRAFORM_COMMAND",
@@ -58,7 +64,9 @@ func addTerraformCommandConfig() {
5864
DefaultValue: "",
5965
})
6066
config.DefaultConfigHandler.BindEnv("components.terraform.apply_auto_approve", "ATMOS_COMPONENTS_TERRAFORM_APPLY_AUTO_APPROVE")
67+
}
6168

69+
func addTerraformInitSettings() {
6270
config.DefaultConfigHandler.AddConfig(terraformCmd, cfg.ConfigOptions{
6371
Key: "components.terraform.init_run_config",
6472
EnvVar: "ATMOS_COMPONENTS_TERRAFORM_INIT_RUN_RECONFIGURE",
@@ -74,10 +82,21 @@ func addTerraformCommandConfig() {
7482
DefaultValue: false,
7583
})
7684
config.DefaultConfigHandler.AddConfig(terraformCmd, cfg.ConfigOptions{
77-
Key: "components.terraform.append_user_agent",
78-
FlagName: "append-user-agent",
79-
EnvVar: "ATMOS_COMPONENTS_TERRAFORM_APPEND_USER_AGENT",
80-
Description: fmt.Sprintf("Sets the TF_APPEND_USER_AGENT environment variable to customize the User-Agent string in Terraform provider requests. Example: `Atmos/%s (Cloud Posse; +https://atmos.tools)`. This flag works with almost all commands.", version.Version),
85+
Key: "components.terraform.init.pass_vars",
86+
FlagName: "init-pass-vars",
87+
EnvVar: "ATMOS_COMPONENTS_TERRAFORM_INIT_PASS_VARS",
88+
Description: "Pass the generated varfile to `terraform init` using the `--var-file` flag. [OpenTofu supports passing a varfile to `init`](https://opentofu.org/docs/cli/commands/init/#general-options) to dynamically configure backends",
89+
DefaultValue: false,
90+
})
91+
}
92+
93+
func addTerraformExecutionSettings() {
94+
config.DefaultConfigHandler.AddConfig(terraformCmd, cfg.ConfigOptions{
95+
Key: "components.terraform.append_user_agent",
96+
FlagName: "append-user-agent",
97+
EnvVar: "ATMOS_COMPONENTS_TERRAFORM_APPEND_USER_AGENT",
98+
DefaultValue: fmt.Sprintf("Atmos/%s (Cloud Posse; +https://atmos.tools)", version.Version),
99+
Description: fmt.Sprintf("Sets the TF_APPEND_USER_AGENT environment variable to customize the User-Agent string in Terraform provider requests. Example: `Atmos/%s (Cloud Posse; +https://atmos.tools)`. This flag works with almost all commands.", version.Version),
81100
})
82101
config.DefaultConfigHandler.AddConfig(terraformCmd, cfg.ConfigOptions{
83102
Key: "components.terraform.skip_init",
@@ -103,13 +122,6 @@ func addTerraformCommandConfig() {
103122
Description: "Skip executing specific YAML functions in the Atmos stack manifests when executing terraform commands",
104123
DefaultValue: []string{},
105124
})
106-
config.DefaultConfigHandler.AddConfig(terraformCmd, cfg.ConfigOptions{
107-
Key: "components.terraform.init.pass_vars",
108-
FlagName: "init-pass-vars",
109-
EnvVar: "ATMOS_COMPONENTS_TERRAFORM_INIT_PASS_VARS",
110-
Description: "Pass the generated varfile to `terraform init` using the `--var-file` flag. [OpenTofu supports passing a varfile to `init`](https://opentofu.org/docs/cli/commands/init/#general-options) to dynamically configure backends",
111-
DefaultValue: false,
112-
})
113125
}
114126

115127
func runHooks(event h.HookEvent, cmd *cobra.Command, args []string) error {

cmd/validate_editorconfig.go

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
u "github.com/cloudposse/atmos/pkg/utils"
1010
"github.com/cloudposse/atmos/pkg/version"
1111

12+
cfg "github.com/cloudposse/atmos/pkg/config"
1213
"github.com/editorconfig-checker/editorconfig-checker/v3/pkg/config"
1314
er "github.com/editorconfig-checker/editorconfig-checker/v3/pkg/error"
1415
"github.com/editorconfig-checker/editorconfig-checker/v3/pkg/files"
@@ -201,4 +202,5 @@ func init() {
201202
addPersistentFlags(editorConfigCmd)
202203
// Add command
203204
validateCmd.AddCommand(editorConfigCmd)
205+
cfg.DefaultConfigHandler.SetDefault("validate.editorconfig.color", true)
204206
}

cmd/workflow.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func init() {
6363
workflowCmd.PersistentFlags().Bool("dry-run", false, "Simulate the workflow without making any changes")
6464
AddStackCompletion(workflowCmd)
6565
workflowCmd.PersistentFlags().String("from-step", "", "Resume the workflow from the specified step")
66-
66+
workflowCommandConfig()
6767
RootCmd.AddCommand(workflowCmd)
6868
}
6969

pkg/config/config_new.go

+12-19
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ import (
1313

1414
var DefaultConfigHandler, err = New()
1515

16-
// ConfigHandler holds the application's configuration
16+
// ConfigHandler holds the application's configuration.
1717
type ConfigHandler struct {
1818
atmosConfig *schema.AtmosConfiguration
1919
v *viper.Viper
2020
}
2121

22-
// ConfigOptions defines options for adding a configuration parameter
22+
// ConfigOptions defines options for adding a configuration parameter.
2323
type ConfigOptions struct {
2424
FlagName string // Custom flag name (optional)
2525
EnvVar string // Custom environment variable (optional)
@@ -28,7 +28,7 @@ type ConfigOptions struct {
2828
DefaultValue interface{} // Default value of the data in atmosConfiguration
2929
}
3030

31-
// New creates a new Config instance with initialized Viper
31+
// New creates a new Config instance with initialized Viper.
3232
func New() (*ConfigHandler, error) {
3333
v := viper.New()
3434
v.SetConfigType("yaml")
@@ -40,7 +40,7 @@ func New() (*ConfigHandler, error) {
4040
return configHandler, configHandler.load()
4141
}
4242

43-
// AddConfig adds a configuration parameter to both Cobra and Viper with options
43+
// AddConfig adds a configuration parameter to both Cobra and Viper with options.
4444
func (c *ConfigHandler) AddConfig(cmd *cobra.Command, opts ConfigOptions) {
4545
key := opts.Key
4646
defaultValue := opts.DefaultValue
@@ -56,33 +56,29 @@ func (c *ConfigHandler) AddConfig(cmd *cobra.Command, opts ConfigOptions) {
5656
// Register flag with Cobra
5757
flagSet := cmd.PersistentFlags()
5858

59-
switch defaultValue.(type) {
59+
switch v := defaultValue.(type) {
6060
case string:
61-
flagSet.String(flagName, defaultValue.(string), opts.Description)
61+
flagSet.String(flagName, v, opts.Description)
6262
case int:
63-
flagSet.Int(flagName, defaultValue.(int), opts.Description)
63+
flagSet.Int(flagName, v, opts.Description)
6464
case bool:
65-
flagSet.Bool(flagName, defaultValue.(bool), opts.Description)
65+
flagSet.Bool(flagName, v, opts.Description)
6666
case []string:
67-
flagSet.StringSlice(flagName, defaultValue.([]string), opts.Description)
67+
flagSet.StringSlice(flagName, v, opts.Description)
6868
default:
69-
panic(fmt.Errorf("unsupported type for key %s", key))
69+
panic(fmt.Sprintf("unsupported type for key %s", key))
7070
}
7171

7272
// Bind the flag to Viper
7373
if err := c.v.BindPFlag(key, flagSet.Lookup(flagName)); err != nil {
74-
panic(fmt.Errorf("failed to bind %s: %w", key, err))
74+
panic(fmt.Sprintf("failed to bind %s: %w", key, err))
7575
}
7676

7777
// Handle environment variable binding
7878
if opts.EnvVar != "" {
7979
if err := c.v.BindEnv(key, opts.EnvVar); err != nil {
8080
panic(err)
8181
}
82-
} else {
83-
if err := c.v.BindEnv(key); err != nil {
84-
panic(err)
85-
}
8682
}
8783

8884
return
@@ -107,10 +103,7 @@ func (c *ConfigHandler) load() error {
107103
c.atmosConfig.CliConfigPath = absPath
108104
}
109105
}
110-
// TODO: This is copy paste need to set this in the right place
111-
// We want the editorconfig color by default to be true
112-
c.atmosConfig.Validate.EditorConfig.Color = true
113-
106+
c.processEnvVars()
114107
viper.AutomaticEnv()
115108

116109
// Unmarshal into AtmosConfiguration struct

0 commit comments

Comments
 (0)