summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@oath.com>2021-09-06 15:07:26 +0200
committerGitHub <noreply@github.com>2021-09-06 15:07:26 +0200
commit88ab0544c7f2ad40eb8183a5bb374052bea511e9 (patch)
tree849161f1a3d531728c8b37447c91e7d7feb69e2d /client
parent5110ea707758589d9834b4c3fef6a4e7316db807 (diff)
parent420e48dcf6acf12ee18c28a73c4ddf9f8f05af77 (diff)
Merge pull request #18978 from vespa-engine/mpolden/vespa-version
vespa version
Diffstat (limited to 'client')
-rw-r--r--client/go/Makefile7
-rw-r--r--client/go/cmd/version.go21
-rw-r--r--client/go/cmd/version_test.go11
-rw-r--r--client/go/util/http.go6
-rw-r--r--client/go/vespa/version.go4
5 files changed, 48 insertions, 1 deletions
diff --git a/client/go/Makefile b/client/go/Makefile
index db16b495b74..abda68427e4 100644
--- a/client/go/Makefile
+++ b/client/go/Makefile
@@ -2,8 +2,13 @@
all: test checkfmt install
+# When building a new release the build system should set the VERSION
+# environment variable to version being built
+VERSION ?= $(shell echo "0.0.0-`git rev-parse --short HEAD`")
+
install:
- env GOBIN=$(PWD)/bin go install ./...
+ env GOBIN=$(PWD)/bin \
+ go install -ldflags "-X github.com/vespa-engine/vespa/client/go/build.Version=$(VERSION)" ./...
test:
go test ./...
diff --git a/client/go/cmd/version.go b/client/go/cmd/version.go
new file mode 100644
index 00000000000..c9146fc1f92
--- /dev/null
+++ b/client/go/cmd/version.go
@@ -0,0 +1,21 @@
+package cmd
+
+import (
+ "log"
+
+ "github.com/spf13/cobra"
+ "github.com/vespa-engine/vespa/client/go/build"
+)
+
+func init() {
+ rootCmd.AddCommand(versionCmd)
+}
+
+var versionCmd = &cobra.Command{
+ Use: "version",
+ Short: "Show version number",
+ Args: cobra.ExactArgs(0),
+ Run: func(cmd *cobra.Command, args []string) {
+ log.Print("vespa version ", build.Version)
+ },
+}
diff --git a/client/go/cmd/version_test.go b/client/go/cmd/version_test.go
new file mode 100644
index 00000000000..02303a08e21
--- /dev/null
+++ b/client/go/cmd/version_test.go
@@ -0,0 +1,11 @@
+package cmd
+
+import (
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestVersion(t *testing.T) {
+ assert.Equal(t, "vespa version 0.0.0-devel\n", execute(command{args: []string{"version"}}, t, nil))
+}
diff --git a/client/go/util/http.go b/client/go/util/http.go
index 4e524fa2d79..a8e2dbc2195 100644
--- a/client/go/util/http.go
+++ b/client/go/util/http.go
@@ -10,6 +10,8 @@ import (
"net/http"
"net/url"
"time"
+
+ "github.com/vespa-engine/vespa/client/go/build"
)
// Set this to a mock HttpClient instead to unit test HTTP requests
@@ -53,6 +55,10 @@ func HttpGet(host string, path string, description string) (*http.Response, erro
}
func HttpDo(request *http.Request, timeout time.Duration, description string) (*http.Response, error) {
+ if request.Header == nil {
+ request.Header = make(http.Header)
+ }
+ request.Header.Set("User-Agent", fmt.Sprintf("Vespa CLI/%s", build.Version))
response, err := ActiveHttpClient.Do(request, timeout)
if err != nil {
return nil, err
diff --git a/client/go/vespa/version.go b/client/go/vespa/version.go
new file mode 100644
index 00000000000..e5a89f4cb58
--- /dev/null
+++ b/client/go/vespa/version.go
@@ -0,0 +1,4 @@
+package vespa
+
+// Version is the Vespa CLI version number
+var Version string = "0.0.0-devel" // Overriden by linker flag as part of build