summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormatthieu <matthieu.cneude@gmail.com>2021-04-04 17:54:29 +0200
committermatthieu <matthieu.cneude@gmail.com>2021-04-04 17:54:29 +0200
commitdd98dc44446d07998b23d47fdd63f2e488ae191e (patch)
treece06a4d9332b7a779f16b68a64bee6e07a09b06a
parentb8d371b335a7969d8ef85b432ea814bf8a392570 (diff)
Add version command
-rw-r--r--.goreleaser.yml2
-rw-r--r--cmd/version.go39
-rwxr-xr-xgoreleaser.sh2
3 files changed, 41 insertions, 2 deletions
diff --git a/.goreleaser.yml b/.goreleaser.yml
index f24ddd4..687e58d 100644
--- a/.goreleaser.yml
+++ b/.goreleaser.yml
@@ -4,11 +4,11 @@ before:
- go mod download
builds:
- id: main
+ ldflags: -s -w -X github.com/Phantas0s/devdash/cmd.current={{.Version}} -X github.com/Phantas0s/devdash/cmd.buildDate={{.Date}}
goos:
- windows
- darwin
- linux
- # main: ./cmd/devdash/devdash.go
env:
- CGO_ENABLED=0
archives:
diff --git a/cmd/version.go b/cmd/version.go
new file mode 100644
index 0000000..548d836
--- /dev/null
+++ b/cmd/version.go
@@ -0,0 +1,39 @@
+package cmd
+
+import (
+ "fmt"
+ "os"
+ "runtime"
+
+ "github.com/spf13/cobra"
+)
+
+var (
+ current string
+ buildDate string
+)
+
+func versionCmd() *cobra.Command {
+ versionCmd := &cobra.Command{
+ Use: "version",
+ Short: "Display gocket version",
+ Run: func(cmd *cobra.Command, args []string) {
+ fmt.Fprintln(os.Stdout, version())
+ },
+ }
+
+ return versionCmd
+}
+
+func version() string {
+ program := "gocket"
+
+ osArch := runtime.GOOS + "/" + runtime.GOARCH
+
+ date := buildDate
+ if date == "" {
+ date = "unknown"
+ }
+
+ return fmt.Sprintf("%s %s %s BuildDate=%s", program, current, osArch, date)
+}
diff --git a/goreleaser.sh b/goreleaser.sh
index f22de67..347b6c0 100755
--- a/goreleaser.sh
+++ b/goreleaser.sh
@@ -1,3 +1,3 @@
#!/bin/bash
-goreleaser && rm -rf dist/ && cd -
+goreleaser && rm -rf dist/