Skip to content

Commit

Permalink
Merge pull request #24 from CircleCI-Public/version-command
Browse files Browse the repository at this point in the history
Add version command
  • Loading branch information
marcomorain authored Jul 17, 2018
2 parents fe0d7e6 + a0beed2 commit 1fd51d2
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,9 @@ builds:
- linux
goarch:
- amd64
ldflags:
# -s Omit the symbol table and debug information.
# -w Omit the DWARF symbol table.
# These are the defaults specified by goreleaser:
# https://github.com/goreleaser/goreleaser/blob/682c811106f56ffe06c4212de546aec62161fb9d/internal/builders/golang/build.go#L46
- -s -w -X version.Version={{.Version}} -X version.Commit={{.Commit}}
3 changes: 2 additions & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"

"github.com/CircleCI-Public/circleci-cli/logger"
"github.com/CircleCI-Public/circleci-cli/version"
"github.com/machinebox/graphql"
)

Expand All @@ -20,14 +21,14 @@ func NewClient(endpoint string, logger *logger.Logger) *graphql.Client {
}

return client

}

// NewAuthorizedRequest returns a new GraphQL request with the
// authorization headers set for CircleCI auth.
func NewAuthorizedRequest(token, query string) *graphql.Request {
req := graphql.NewRequest(query)
req.Header.Set("Authorization", token)
req.Header.Set("User-Agent", fmt.Sprintf("circleci-cli/%s-%s", version.Version, version.Commit))
return req
}

Expand Down
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func MakeCommands() *cobra.Command {
rootCmd.AddCommand(newConfigCommand())
rootCmd.AddCommand(newOrbCommand())
rootCmd.AddCommand(newBuildCommand())
rootCmd.AddCommand(newVersionCommand())
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
2 changes: 1 addition & 1 deletion cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var _ = Describe("Root", func() {

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

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

import (
"github.com/CircleCI-Public/circleci-cli/version"
"github.com/spf13/cobra"
)

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

}
9 changes: 9 additions & 0 deletions version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package version

// These vars set by `goreleaser`:
var (
// Version is the 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"
// Commit is the current git commit SHA
Commit = "dirty-local-tree"
)

0 comments on commit 1fd51d2

Please sign in to comment.