Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for atlantis version #852

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cmd/atlantis.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"github.com/cloudposse/atmos/internal/exec"
"github.com/spf13/cobra"
)

Expand All @@ -10,6 +11,9 @@ var atlantisCmd = &cobra.Command{
Short: "Execute 'atlantis' commands",
Long: `This command executes Atlantis integration commands`,
FParseErrWhitelist: struct{ UnknownFlags bool }{UnknownFlags: false},
Run: func(cmd *cobra.Command, args []string) {
exec.ExecuteAtlantis(cmd, args)
},
Comment on lines +14 to +16
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Handle the error returned by ExecuteAtlantis

The error returned by ExecuteAtlantis should be checked and handled appropriately to prevent silent failures.

Apply this diff to handle the error:

Run: func(cmd *cobra.Command, args []string) {
-    exec.ExecuteAtlantis(cmd, args)
+    if err := exec.ExecuteAtlantis(cmd, args); err != nil {
+        fmt.Fprintf(os.Stderr, "Error executing atlantis command: %v\n", err)
+        os.Exit(1)
+    }
},
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Run: func(cmd *cobra.Command, args []string) {
exec.ExecuteAtlantis(cmd, args)
},
Run: func(cmd *cobra.Command, args []string) {
if err := exec.ExecuteAtlantis(cmd, args); err != nil {
fmt.Fprintf(os.Stderr, "Error executing atlantis command: %v\n", err)
os.Exit(1)
}
},
🧰 Tools
🪛 golangci-lint (1.62.2)

15-15: Error return value of exec.ExecuteAtlantis is not checked

(errcheck)

}

func init() {
Expand Down
14 changes: 14 additions & 0 deletions internal/exec/atlantis_generate_repo_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ import (
u "github.com/cloudposse/atmos/pkg/utils"
)

// ExecuteAtlantis executes atlantis command
func ExecuteAtlantis(cmd *cobra.Command, args []string) error {
info, err := ProcessCommandLineArgs("atlantis", cmd, args, nil)
if err != nil {
return err
}

cliConfig, err := cfg.InitCliConfig(info, true)
if err != nil {
return err
}
return ExecuteShellCommand(cliConfig, "atlantis", args, "", nil, false, "")
}

// ExecuteAtlantisGenerateRepoConfigCmd executes 'atlantis generate repo-config' command
func ExecuteAtlantisGenerateRepoConfigCmd(cmd *cobra.Command, args []string) error {
info, err := ProcessCommandLineArgs("", cmd, args, nil)
Expand Down
13 changes: 6 additions & 7 deletions internal/exec/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -661,22 +661,21 @@ func processArgsAndFlags(componentType string, inputArgsAndFlags []string) (sche
var indexesToRemove []int

// For commands like `atmos terraform clean` and `atmos terraform plan`, show the command help
if len(inputArgsAndFlags) == 1 {
if len(inputArgsAndFlags) == 1 && inputArgsAndFlags[0] != "version" {
info.SubCommand = inputArgsAndFlags[0]
info.NeedHelp = true
return info, nil
}

// https://github.com/roboll/helmfile#cli-reference
var globalOptionsFlagIndex int

// For commands like `atmos terraform clean` and `atmos terraform plan`, show the command help
if len(inputArgsAndFlags) == 1 {
// For version commands `atmos terraform version` or `atmos atlantis version`
if len(inputArgsAndFlags) == 1 && inputArgsAndFlags[0] == "version" {
info.SubCommand = inputArgsAndFlags[0]
info.NeedHelp = true
return info, nil
}

// https://github.com/roboll/helmfile#cli-reference
var globalOptionsFlagIndex int

for i, arg := range inputArgsAndFlags {
if arg == cfg.GlobalOptionsFlag {
globalOptionsFlagIndex = i + 1
Expand Down
Loading