Skip to content

Commit

Permalink
add version subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Fuentes committed Mar 23, 2018
1 parent 8b9b0a8 commit f450832
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
12 changes: 7 additions & 5 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ var (
validKeyFormat = regexp.MustCompile(`^[A-Za-z0-9-_]+$`)
validServiceFormat = regexp.MustCompile(`^[A-Za-z0-9-_]+$`)

numRetries int
numRetries int
chamberVersion string
)

const (
Expand All @@ -27,9 +28,9 @@ const (

// RootCmd represents the base command when called without any subcommands
var RootCmd = &cobra.Command{
Use: "chamber",
Short: "CLI for storing secrets",
SilenceUsage: true,
Use: "chamber",
Short: "CLI for storing secrets",
SilenceUsage: true,
}

func init() {
Expand All @@ -38,7 +39,8 @@ func init() {

// Execute adds all child commands to the root command sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
func Execute(vers string) {
chamberVersion = vers
if cmd, err := RootCmd.ExecuteC(); err != nil {
if strings.Contains(err.Error(), "arg(s)") || strings.Contains(err.Error(), "usage") {
cmd.Usage()
Expand Down
24 changes: 24 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package cmd

import (
"fmt"
"os"

"github.com/spf13/cobra"
)

// versionCmd represents the version command
var versionCmd = &cobra.Command{
Use: "version",
Short: "print version",
RunE: versionRun,
}

func init() {
RootCmd.AddCommand(versionCmd)
}

func versionRun(cmd *cobra.Command, args []string) error {
fmt.Fprintf(os.Stdout, "chamber %s\n", chamberVersion)
return nil
}
7 changes: 6 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ package main

import "github.com/segmentio/chamber/cmd"

var (
// This is updated by linker flags during build
Version = "dev"
)

func main() {
cmd.Execute()
cmd.Execute(Version)
}

0 comments on commit f450832

Please sign in to comment.