Skip to content

Commit

Permalink
add --version flag
Browse files Browse the repository at this point in the history
  • Loading branch information
xrstf committed Jul 24, 2023
1 parent 3f3eea6 commit bd8e3d0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ builds:
flags:
- -trimpath
ldflags:
- '-s -w -X main.version={{.Version}} -X main.commit={{.Commit}}'
- '-s -w -X main.Tag={{.Version}} -X main.Commit={{.Commit}}'
goos:
- freebsd
- windows
Expand Down
25 changes: 25 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"context"
"fmt"
"os"
"runtime"
"strings"
"time"

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

// Project build specific vars
var (
Tag string
Commit string
)

func printVersion() {
fmt.Printf(
"version: %s\nbuilt with: %s\ntag: %s\ncommit: %s\n",
strings.TrimPrefix(Tag, "v"),
runtime.Version(),
Tag,
Commit,
)
}

type options struct {
kubeconfig string
directory string
Expand All @@ -41,6 +59,7 @@ type options struct {
dumpEvents bool
dumpRawEvents bool
verbose bool
version bool
}

func main() {
Expand All @@ -63,8 +82,14 @@ func main() {
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)")
pflag.BoolVar(&opt.dumpRawEvents, "events-raw", opt.dumpRawEvents, "Dump events for each matching Pod as YAML (note: label selectors are not respected)")
pflag.BoolVarP(&opt.verbose, "verbose", "v", opt.verbose, "Enable more verbose output")
pflag.BoolVarP(&opt.version, "version", "V", opt.version, "Show version info and exit immediately")
pflag.Parse()

if opt.version {
printVersion()
return
}

// //////////////////////////////////////
// setup logging

Expand Down

0 comments on commit bd8e3d0

Please sign in to comment.