Skip to content
This repository was archived by the owner on Dec 9, 2023. It is now read-only.

Commit dd98dc4

Browse files
committed
Add version command
1 parent b8d371b commit dd98dc4

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

.goreleaser.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ before:
44
- go mod download
55
builds:
66
- id: main
7+
ldflags: -s -w -X github.com/Phantas0s/devdash/cmd.current={{.Version}} -X github.com/Phantas0s/devdash/cmd.buildDate={{.Date}}
78
goos:
89
- windows
910
- darwin
1011
- linux
11-
# main: ./cmd/devdash/devdash.go
1212
env:
1313
- CGO_ENABLED=0
1414
archives:

cmd/version.go

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"runtime"
7+
8+
"github.com/spf13/cobra"
9+
)
10+
11+
var (
12+
current string
13+
buildDate string
14+
)
15+
16+
func versionCmd() *cobra.Command {
17+
versionCmd := &cobra.Command{
18+
Use: "version",
19+
Short: "Display gocket version",
20+
Run: func(cmd *cobra.Command, args []string) {
21+
fmt.Fprintln(os.Stdout, version())
22+
},
23+
}
24+
25+
return versionCmd
26+
}
27+
28+
func version() string {
29+
program := "gocket"
30+
31+
osArch := runtime.GOOS + "/" + runtime.GOARCH
32+
33+
date := buildDate
34+
if date == "" {
35+
date = "unknown"
36+
}
37+
38+
return fmt.Sprintf("%s %s %s BuildDate=%s", program, current, osArch, date)
39+
}

goreleaser.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/bin/bash
22

3-
goreleaser && rm -rf dist/ && cd -
3+
goreleaser && rm -rf dist/

0 commit comments

Comments
 (0)