Skip to content

Commit

Permalink
fixes for terraform help
Browse files Browse the repository at this point in the history
  • Loading branch information
Cerebrovinny committed Nov 21, 2024
1 parent a564308 commit fccd816
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
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
}

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

0 comments on commit fccd816

Please sign in to comment.