Skip to content

Commit

Permalink
Merge pull request #2187 from sayboras/bugfix/version-flags
Browse files Browse the repository at this point in the history
Fix flags issue in version cli
  • Loading branch information
martina-if authored May 15, 2020
2 parents 44e4660 + e9167b8 commit 2a65f11
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
3 changes: 2 additions & 1 deletion cmd/eksctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ func addCommands(rootCmd *cobra.Command, flagGrouping *cmdutils.FlagGrouping) {
}
rootCmd.AddCommand(utils.Command(flagGrouping))
rootCmd.AddCommand(completion.Command(rootCmd))
rootCmd.AddCommand(versionCmd(flagGrouping))

cmdutils.AddResourceCmd(flagGrouping, rootCmd, versionCmd)
}

func main() {
Expand Down
37 changes: 19 additions & 18 deletions cmd/eksctl/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,31 @@ package main
import (
"fmt"

"github.com/spf13/pflag"

"github.com/spf13/cobra"

"github.com/weaveworks/eksctl/pkg/ctl/cmdutils"
"github.com/weaveworks/eksctl/pkg/version"
)

var output string
func versionCmd(cmd *cmdutils.Cmd) {
var output string

func versionCmd(_ *cmdutils.FlagGrouping) *cobra.Command {
cmd := &cobra.Command{
Use: "version",
Short: "Output the version of eksctl",
RunE: func(_ *cobra.Command, _ []string) error {
switch output {
case "":
fmt.Printf("%s\n", version.GetVersion())
case "json":
fmt.Printf("%s\n", version.String())
default:
return fmt.Errorf("unknown output: %s", output)
}
return nil
},
cmd.SetDescription("version", "Output the version of eksctl", "")
cmd.FlagSetGroup.InFlagSet("General", func(fs *pflag.FlagSet) {
fs.StringVarP(&output, "output", "o", "", "specifies the output format (valid option: json)")
})
cmd.CobraCommand.Args = cobra.NoArgs
cmd.CobraCommand.RunE = func(_ *cobra.Command, args []string) error {
switch output {
case "":
fmt.Printf("%s\n", version.GetVersion())
case "json":
fmt.Printf("%s\n", version.String())
default:
return fmt.Errorf("unknown output: %s", output)
}
return nil
}
cmd.Flags().StringVarP(&output, "output", "o", "", "specifies the output format (valid option: json)")
return cmd
}

0 comments on commit 2a65f11

Please sign in to comment.