-
Notifications
You must be signed in to change notification settings - Fork 21
/
terraform.go
67 lines (55 loc) · 1.58 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
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 command
import (
"flag"
"strings"
"github.com/minamijoyo/tfupdate/tfupdate"
)
// TerraformCommand is a command which update version constraints for terraform.
type TerraformCommand struct {
Meta
target string
path string
recursive bool
}
// Run runs the procedure of this command.
func (c *TerraformCommand) Run(args []string) int {
cmdFlags := flag.NewFlagSet("terraform", flag.ContinueOnError)
cmdFlags.StringVar(&c.target, "v", "", "A new version constraint")
cmdFlags.StringVar(&c.path, "f", "./", "A path of file or directory to update")
cmdFlags.BoolVar(&c.recursive, "r", false, "Check a directory recursively")
if err := cmdFlags.Parse(args); err != nil {
return 1
}
if len(cmdFlags.Args()) != 0 {
c.UI.Error("The provider command expects no arguments")
c.UI.Error(c.Help())
return 1
}
if len(c.target) == 0 {
c.UI.Error("Argument error: -v is required\n")
c.UI.Error(c.Help())
return 1
}
option := tfupdate.NewOption("terraform", c.target, c.recursive)
err := tfupdate.UpdateFileOrDir(c.Fs, c.path, option)
if err != nil {
c.UI.Error(err.Error())
return 1
}
return 0
}
// Help returns long-form help text.
func (c *TerraformCommand) Help() string {
helpText := `
Usage: tfupdate terraform [options]
Options:
-v A new version constraint
-f A path of file or directory to update (default: ./)
-r Check a directory recursively (default: false)
`
return strings.TrimSpace(helpText)
}
// Synopsis returns one-line help text.
func (c *TerraformCommand) Synopsis() string {
return "Update version constraints for terraform"
}