Skip to content
This repository was archived by the owner on Mar 14, 2025. It is now read-only.

Commit bd8e3d0

Browse files
committed
add --version flag
1 parent 3f3eea6 commit bd8e3d0

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

.goreleaser.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ builds:
88
flags:
99
- -trimpath
1010
ldflags:
11-
- '-s -w -X main.version={{.Version}} -X main.commit={{.Commit}}'
11+
- '-s -w -X main.Tag={{.Version}} -X main.Commit={{.Commit}}'
1212
goos:
1313
- freebsd
1414
- windows

main.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77
"context"
88
"fmt"
99
"os"
10+
"runtime"
11+
"strings"
1012
"time"
1113

1214
"go.xrstf.de/protokol/pkg/collector"
@@ -26,6 +28,22 @@ import (
2628
watchtools "k8s.io/client-go/tools/watch"
2729
)
2830

31+
// Project build specific vars
32+
var (
33+
Tag string
34+
Commit string
35+
)
36+
37+
func printVersion() {
38+
fmt.Printf(
39+
"version: %s\nbuilt with: %s\ntag: %s\ncommit: %s\n",
40+
strings.TrimPrefix(Tag, "v"),
41+
runtime.Version(),
42+
Tag,
43+
Commit,
44+
)
45+
}
46+
2947
type options struct {
3048
kubeconfig string
3149
directory string
@@ -41,6 +59,7 @@ type options struct {
4159
dumpEvents bool
4260
dumpRawEvents bool
4361
verbose bool
62+
version bool
4463
}
4564

4665
func main() {
@@ -63,8 +82,14 @@ func main() {
6382
pflag.BoolVar(&opt.dumpEvents, "events", opt.dumpEvents, "Dump events for each matching Pod as a human readable log file (note: label selectors are not respected)")
6483
pflag.BoolVar(&opt.dumpRawEvents, "events-raw", opt.dumpRawEvents, "Dump events for each matching Pod as YAML (note: label selectors are not respected)")
6584
pflag.BoolVarP(&opt.verbose, "verbose", "v", opt.verbose, "Enable more verbose output")
85+
pflag.BoolVarP(&opt.version, "version", "V", opt.version, "Show version info and exit immediately")
6686
pflag.Parse()
6787

88+
if opt.version {
89+
printVersion()
90+
return
91+
}
92+
6893
// //////////////////////////////////////
6994
// setup logging
7095

0 commit comments

Comments
 (0)