Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add version command #24

Merged
merged 1 commit into from
Jul 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
)