Skip to content

Commit

Permalink
Add version command
Browse files Browse the repository at this point in the history
  • Loading branch information
marcomorain committed Jul 17, 2018
1 parent fe0d7e6 commit 255052f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
7 changes: 4 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ var configPath = ".circleci/config.yml"
// sets flags appropriately. This function is called
// by main.main(). It only needs to happen once to
// the RootCmd.
func Execute() {
command := MakeCommands()
func Execute(version, commit string) {
command := MakeCommands(version, commit)
if err := command.Execute(); err != nil {
os.Exit(-1)
}
Expand All @@ -32,7 +32,7 @@ func Execute() {
var Logger *logger.Logger

// MakeCommands creates the top level commands
func MakeCommands() *cobra.Command {
func MakeCommands(version, commit string) *cobra.Command {

rootCmd := &cobra.Command{
Use: "circleci",
Expand All @@ -47,6 +47,7 @@ func MakeCommands() *cobra.Command {
rootCmd.AddCommand(newConfigCommand())
rootCmd.AddCommand(newOrbCommand())
rootCmd.AddCommand(newBuildCommand())
rootCmd.AddCommand(newVersionCommand(version, commit))
rootCmd.PersistentFlags().BoolP("verbose", "v", false, "Enable verbose logging.")
rootCmd.PersistentFlags().StringP("endpoint", "e", defaultEndpoint, "the endpoint of your CircleCI GraphQL API")
rootCmd.PersistentFlags().StringP("token", "t", "", "your token for using CircleCI")
Expand Down
4 changes: 2 additions & 2 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ var _ = Describe("Root", func() {
Describe("subcommands", func() {

It("can create commands", func() {
commands := cmd.MakeCommands()
Expect(len(commands.Commands())).To(Equal(7))
commands := cmd.MakeCommands("foo", "bar")
Expect(len(commands.Commands())).To(Equal(8))
})

})
Expand Down
14 changes: 14 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package cmd

import "github.com/spf13/cobra"

func newVersionCommand(version, commit string) *cobra.Command {
return &cobra.Command{
Use: "version",
Short: "Display version information",
Run: func(cmd *cobra.Command, args []string) {
Logger.Infof("%s (%s)", version, commit)
},
}

}
10 changes: 9 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@ import (
"github.com/CircleCI-Public/circleci-cli/cmd"
)

// vars set automatically by `goreleaser`:
var (
// Current Git tag (the v prefix is stripped) or the name of the snapshot, if you’re using the --snapshot flag
version = "local-dev-build"
// Current git commit SHA
commit = "dirty-local-tree"
)

func main() {
// See cmd/root.go for Execute()
cmd.Execute()
cmd.Execute(version, commit)
}

0 comments on commit 255052f

Please sign in to comment.