Skip to content

Commit

Permalink
Change a version constraint from an argument to a flag
Browse files Browse the repository at this point in the history
  • Loading branch information
minamijoyo committed Sep 12, 2019
1 parent 6f16007 commit 264031a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
17 changes: 10 additions & 7 deletions command/provider.go
Expand Up @@ -10,26 +10,28 @@ import (
// ProviderCommand is a command which update version constraints for provider.
type ProviderCommand struct {
Meta
path string
target string
path string
}

// Run runs the procedure of this command.
func (c *ProviderCommand) Run(args []string) int {
cmdFlags := flag.NewFlagSet("provider", flag.ContinueOnError)
cmdFlags.StringVar(&c.target, "v", "", "A new version constraint")
cmdFlags.StringVar(&c.path, "f", "main.tf", "A path to filename to update")

if err := cmdFlags.Parse(args); err != nil {
return 1
}

if len(cmdFlags.Args()) != 1 {
c.UI.Error("The provider command expects <NAME>@<VERSION>")
if len(cmdFlags.Args()) != 0 {
c.UI.Error("The provider command expects no arguments")
c.UI.Error(c.Help())
return 1
}

updateType := "provider"
target := cmdFlags.Args()[0]
target := c.target
filename := c.path

option := tfupdate.NewOption(updateType, target)
Expand All @@ -45,11 +47,12 @@ func (c *ProviderCommand) Run(args []string) int {
// Help returns long-form help text.
func (c *ProviderCommand) Help() string {
helpText := `
Usage: tfupdate provider [options] <NAME>@<VERSION>
Usage: tfupdate provider [options]
Options:
-f=path A path to filename to update
-v A new version constraint.
The valid format is <PROVIER_NAME>@<VERSION>
-f A path to filename to update
`
return strings.TrimSpace(helpText)
}
Expand Down
16 changes: 9 additions & 7 deletions command/terraform.go
Expand Up @@ -10,26 +10,28 @@ import (
// TerraformCommand is a command which update version constraints for terraform.
type TerraformCommand struct {
Meta
path string
target string
path string
}

// 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", "main.tf", "A path to filename to update")

if err := cmdFlags.Parse(args); err != nil {
return 1
}

if len(cmdFlags.Args()) != 1 {
c.UI.Error("The terraform command expects <VERSION>")
if len(cmdFlags.Args()) != 0 {
c.UI.Error("The provider command expects no arguments")
c.UI.Error(c.Help())
return 1
}

updateType := "terraform"
target := cmdFlags.Args()[0]
target := c.target
filename := c.path

option := tfupdate.NewOption(updateType, target)
Expand All @@ -45,11 +47,11 @@ func (c *TerraformCommand) Run(args []string) int {
// Help returns long-form help text.
func (c *TerraformCommand) Help() string {
helpText := `
Usage: tfupdate terraform [options] <VERSION>
Usage: tfupdate terraform [options]
Options:
-f=path A path to filename to update
-v A new version constraint
-f A path to filename to update
`
return strings.TrimSpace(helpText)
}
Expand Down

0 comments on commit 264031a

Please sign in to comment.