Skip to content

Commit 24885c6

Browse files
committed
Add version command
1 parent 1f1f9ba commit 24885c6

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

.goreleaser.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
project_name: pcert
22
builds:
33
- main: ./cmd/pcert/
4+
ldflags:
5+
- -s -w
6+
- -X main.version={{.Version}}
7+
- -X main.commit={{.Commit}}
48
goos:
59
- linux
610
- darwin

cmd/pcert/main.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ const (
2020
csrFileSuffix = ".csr"
2121
)
2222

23+
var (
24+
version = "n/a"
25+
commit = "n/a"
26+
)
27+
2328
type app struct {
2429
// signer settings
2530
signCertFile string
@@ -192,10 +197,22 @@ prefix (e.g PCERT_CERT instad of --cert).`,
192197
newSignCmd(cfg),
193198
newListCmd(),
194199
newCompletionCmd(),
200+
newVersionCmd(),
195201
)
196202
return cmd
197203
}
198204

205+
func newVersionCmd() *cobra.Command {
206+
cmd := &cobra.Command{
207+
Use: "version",
208+
RunE: func(cmd *cobra.Command, args []string) error {
209+
fmt.Println("pcert", version, commit)
210+
return nil
211+
},
212+
}
213+
return cmd
214+
}
215+
199216
func newCompletionCmd() *cobra.Command {
200217
var shell string
201218
cmd := &cobra.Command{

0 commit comments

Comments
 (0)