-
-
Notifications
You must be signed in to change notification settings - Fork 91
/
terraform.go
40 lines (34 loc) · 1.19 KB
/
terraform.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package cmd
import (
"github.com/samber/lo"
"github.com/spf13/cobra"
e "github.com/cloudposse/atmos/internal/exec"
u "github.com/cloudposse/atmos/pkg/utils"
)
// terraformCmd represents the base command for all terraform sub-commands
var terraformCmd = &cobra.Command{
Use: "terraform",
Aliases: []string{"tf"},
Short: "Execute 'terraform' commands",
Long: `This command executes 'terraform'' commands`,
FParseErrWhitelist: struct{ UnknownFlags bool }{UnknownFlags: true},
Run: func(cmd *cobra.Command, args []string) {
var argsAfterDoubleDash []string
var finalArgs = args
doubleDashIndex := lo.IndexOf(args, "--")
if doubleDashIndex > 0 {
finalArgs = lo.Slice(args, 0, doubleDashIndex)
argsAfterDoubleDash = lo.Slice(args, doubleDashIndex+1, len(args))
}
err := e.ExecuteTerraformCmd(cmd, finalArgs, argsAfterDoubleDash)
if err != nil {
u.LogErrorAndExit(err)
}
},
}
func init() {
// https://github.com/spf13/cobra/issues/739
terraformCmd.DisableFlagParsing = true
terraformCmd.PersistentFlags().StringP("stack", "s", "", "atmos terraform <terraform_command> <component> -s <stack>")
RootCmd.AddCommand(terraformCmd)
}