-
Notifications
You must be signed in to change notification settings - Fork 3
/
filter.go
67 lines (54 loc) · 1.46 KB
/
filter.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package cmd
import (
"fmt"
"github.com/minamijoyo/tfedit/filter"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
func init() {
filterCmd := newFilterCmd()
flags := filterCmd.PersistentFlags()
flags.StringP("file", "f", "-", "A path to input Terraform configuration file")
flags.BoolP("update", "u", false, "Update files in-place")
_ = viper.BindPFlag("file", flags.Lookup("file"))
_ = viper.BindPFlag("update", flags.Lookup("update"))
RootCmd.AddCommand(filterCmd)
}
func newFilterCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "filter",
Short: "Apply a built-in filter",
RunE: func(cmd *cobra.Command, args []string) error {
return cmd.Help()
},
}
cmd.AddCommand(
newFilterAwsv4upgradeCmd(),
)
return cmd
}
func newFilterAwsv4upgradeCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "awsv4upgrade",
Short: "Apply a built-in filter for awsv4upgrade",
Long: `Apply a built-in filter for awsv4upgrade
Upgrade configurations to AWS provider v4.
Only aws_s3_bucket refactor is supported.
`,
RunE: runFilterAwsv4upgradeCmd,
}
return cmd
}
func runFilterAwsv4upgradeCmd(cmd *cobra.Command, args []string) error {
if len(args) != 0 {
return fmt.Errorf("expected 0 argument, but got %d arguments", len(args))
}
file := viper.GetString("file")
update := viper.GetBool("update")
filter, err := filter.NewFilterByType("awsv4upgrade")
if err != nil {
return err
}
c := newDefaultClient(cmd)
return c.Edit(file, update, filter)
}