Skip to content

Commit

Permalink
Add -v flag for version (#73)
Browse files Browse the repository at this point in the history
* Add -v flag for version

* Add a comment explaining how the version flag is set
  • Loading branch information
tomer-stripe committed Aug 2, 2019
1 parent d2c89f3 commit 0e8c9d4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 2 additions & 0 deletions pkg/cmd/root.go
Expand Up @@ -94,6 +94,7 @@ Use "{{.CommandPath}} [command] --help" for more information about a command.{{e
ansi.Bold("Global flags:"),
ansi.Bold("Additional help topics:"),
))
rootCmd.SetVersionTemplate(version.Template)
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
Expand All @@ -110,6 +111,7 @@ func init() {

rootCmd.PersistentFlags().StringVar(&Config.Profile.ProfileName, "project-name", "default", "the project name to read from for config")
rootCmd.PersistentFlags().StringVar(&Config.Profile.DeviceName, "device-name", "", "device name")
rootCmd.Flags().BoolP("version", "v", false, "Get the version of the Stripe CLI")

viper.BindPFlag("secret_key", rootCmd.PersistentFlags().Lookup("api-key")) // #nosec G104

Expand Down
3 changes: 1 addition & 2 deletions pkg/cmd/version.go
Expand Up @@ -5,7 +5,6 @@ import (

"github.com/spf13/cobra"

"github.com/stripe/stripe-cli/pkg/ansi"
"github.com/stripe/stripe-cli/pkg/validators"
"github.com/stripe/stripe-cli/pkg/version"
)
Expand All @@ -21,7 +20,7 @@ func newVersionCmd() *versionCmd {
Args: validators.NoArgs,
Short: "Get the version of the Stripe CLI",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(fmt.Sprintf("stripe version "+version.Version+" %s", ansi.Bold("(beta)")))
fmt.Print(version.Template)
},
},
}
Expand Down
13 changes: 12 additions & 1 deletion pkg/version/version.go
@@ -1,4 +1,15 @@
package version

// Version number of the CLI
import (
"fmt"

"github.com/stripe/stripe-cli/pkg/ansi"
)

// Version of the CLI -- currently in beta
// This is set to the actual version by GoReleaser, identify by the
// git tag assigned to the release Versions built from source will
// always show master.
var Version = "master"

var Template = fmt.Sprintf("stripe version %s %s\n", Version, ansi.Bold("(beta)"))

0 comments on commit 0e8c9d4

Please sign in to comment.