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

Fix Terraform help printing log twice and causing error #798

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 1 addition & 4 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ var RootCmd = &cobra.Command{
err := tuiUtils.PrintStyledText("ATMOS")
if err != nil {
u.LogErrorAndExit(schema.CliConfiguration{}, err)
return
}

err = e.ExecuteAtmosCmd()
Expand All @@ -73,10 +74,6 @@ func Execute() error {
err := RootCmd.ParseFlags(os.Args)
if err != nil && errors.Is(err, pflag.ErrHelp) {
fmt.Println()
err = tuiUtils.PrintStyledText("ATMOS")
if err != nil {
u.LogErrorAndExit(schema.CliConfiguration{}, err)
}
}

// InitCliConfig finds and merges CLI configurations in the following order:
Expand Down
9 changes: 9 additions & 0 deletions cmd/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ var terraformCmd = &cobra.Command{
Long: `This command executes Terraform commands`,
FParseErrWhitelist: struct{ UnknownFlags bool }{UnknownFlags: true},
Run: func(cmd *cobra.Command, args []string) {
// Check if help is requested
if cmd.Flags().Changed("help") || (len(args) > 0 && args[0] == "help") {
err := e.ExecuteTerraformCmd(cmd, args, nil)
if err != nil {
u.LogErrorAndExit(schema.CliConfiguration{}, err)
}
return
}

// Check Atmos configuration
checkAtmosConfig()

Expand Down
21 changes: 17 additions & 4 deletions internal/exec/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,28 @@ func ExecuteTerraformCmd(cmd *cobra.Command, args []string, additionalArgsAndFla

// ExecuteTerraform executes terraform commands
func ExecuteTerraform(info schema.ConfigAndStacksInfo) error {
// Don't require config to process the terraform command
if info.NeedHelp {
fmt.Println()
err := tuiUtils.PrintStyledText("ATMOS")
if err != nil {
return err
}

err = processHelp(schema.CliConfiguration{}, "terraform", "")
if err != nil {
return err
}

fmt.Println()
return nil
}
Cerebrovinny marked this conversation as resolved.
Show resolved Hide resolved

cliConfig, err := cfg.InitCliConfig(info, true)
if err != nil {
return err
}

if info.NeedHelp {
return nil
}

// If the user just types `atmos terraform`, print Atmos logo and show terraform help
if info.SubCommand == "" {
fmt.Println()
Expand Down