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

Commit 16f5637

Browse files
committed
add --version
1 parent a91b001 commit 16f5637

File tree

3 files changed

+41
-13
lines changed

3 files changed

+41
-13
lines changed

.goreleaser.yml

+3-1
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
@@ -22,6 +22,8 @@ builds:
2222
ignore:
2323
- goos: darwin
2424
goarch: '386'
25+
- goos: freebsd
26+
goarch: '386'
2527
binary: '{{ .ProjectName }}'
2628
archives:
2729
- format: zip

README.md

+7-6
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,18 @@ go install go.xrstf.de/stalk
2020

2121
```
2222
Usage of ./stalk:
23-
-c, --context-lines int number of context lines to show in diffs (default 3)
24-
-w, --diff-by-line diff entire lines and do not highlight changes within words
25-
-h, --hide stringArray path expression to hide in output (can be given multiple times)
23+
-c, --context-lines int Number of context lines to show in diffs (default 3)
24+
-w, --diff-by-line Compare entire lines and do not highlight changes within words
25+
-h, --hide stringArray Path expression to hide in output (can be given multiple times)
2626
--hide-managed Do not show managed fields (default true)
2727
-j, --jsonpath string JSON path expression to transform the output (applied before the --show paths)
28-
--kubeconfig string kubeconfig file to use (uses $KUBECONFIG by default)
28+
--kubeconfig string Kubeconfig file to use (uses $KUBECONFIG by default)
2929
-l, --labels string Label-selector as an alternative to specifying resource names
3030
-n, --namespace stringArray Kubernetes namespace to watch resources in (supports glob expression) (can be given multiple times)
31-
-s, --show stringArray path expression to include in output (can be given multiple times) (applied before the --hide paths)
32-
-e, --show-empty do not hide changes which would produce no diff because of --hide/--show/--jsonpath
31+
-s, --show stringArray Path expression to include in output (can be given multiple times) (applied before the --hide paths)
32+
-e, --show-empty Do not hide changes which would produce no diff because of --hide/--show/--jsonpath
3333
-v, --verbose Enable more verbose output
34+
-V, --version Show version info and exit immediately
3435
```
3536

3637
## Examples

main.go

+31-6
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ package main
22

33
import (
44
"context"
5+
"fmt"
56
"io"
67
"os"
8+
"runtime"
79
"strings"
810
"sync"
911
"time"
@@ -24,6 +26,22 @@ import (
2426
"k8s.io/client-go/tools/clientcmd"
2527
)
2628

29+
// Project build specific vars
30+
var (
31+
Tag string
32+
Commit string
33+
)
34+
35+
func printVersion() {
36+
fmt.Printf(
37+
"version: %s\nbuilt with: %s\ntag: %s\ncommit: %s\n",
38+
strings.TrimPrefix(Tag, "v"),
39+
runtime.Version(),
40+
Tag,
41+
Commit,
42+
)
43+
}
44+
2745
type options struct {
2846
kubeconfig string
2947
namespaces []string
@@ -37,6 +55,7 @@ type options struct {
3755
disableWordDiff bool
3856
contextLines int
3957
verbose bool
58+
version bool
4059
}
4160

4261
func main() {
@@ -49,19 +68,25 @@ func main() {
4968
contextLines: 3,
5069
}
5170

52-
pflag.StringVar(&opt.kubeconfig, "kubeconfig", opt.kubeconfig, "kubeconfig file to use (uses $KUBECONFIG by default)")
71+
pflag.StringVar(&opt.kubeconfig, "kubeconfig", opt.kubeconfig, "Kubeconfig file to use (uses $KUBECONFIG by default)")
5372
pflag.StringArrayVarP(&opt.namespaces, "namespace", "n", opt.namespaces, "Kubernetes namespace to watch resources in (supports glob expression) (can be given multiple times)")
5473
pflag.StringVarP(&opt.labels, "labels", "l", opt.labels, "Label-selector as an alternative to specifying resource names")
5574
pflag.BoolVar(&opt.hideManagedFields, "hide-managed", opt.hideManagedFields, "Do not show managed fields")
5675
pflag.StringVarP(&opt.jsonPath, "jsonpath", "j", opt.jsonPath, "JSON path expression to transform the output (applied before the --show paths)")
57-
pflag.StringArrayVarP(&opt.showPaths, "show", "s", opt.showPaths, "path expression to include in output (can be given multiple times) (applied before the --hide paths)")
58-
pflag.StringArrayVarP(&opt.hidePaths, "hide", "h", opt.hidePaths, "path expression to hide in output (can be given multiple times)")
59-
pflag.BoolVarP(&opt.showEmpty, "show-empty", "e", opt.showEmpty, "do not hide changes which would produce no diff because of --hide/--show/--jsonpath")
60-
pflag.BoolVarP(&opt.disableWordDiff, "diff-by-line", "w", opt.disableWordDiff, "diff entire lines and do not highlight changes within words")
61-
pflag.IntVarP(&opt.contextLines, "context-lines", "c", opt.contextLines, "number of context lines to show in diffs")
76+
pflag.StringArrayVarP(&opt.showPaths, "show", "s", opt.showPaths, "Path expression to include in output (can be given multiple times) (applied before the --hide paths)")
77+
pflag.StringArrayVarP(&opt.hidePaths, "hide", "h", opt.hidePaths, "Path expression to hide in output (can be given multiple times)")
78+
pflag.BoolVarP(&opt.showEmpty, "show-empty", "e", opt.showEmpty, "Do not hide changes which would produce no diff because of --hide/--show/--jsonpath")
79+
pflag.BoolVarP(&opt.disableWordDiff, "diff-by-line", "w", opt.disableWordDiff, "Compare entire lines and do not highlight changes within words")
80+
pflag.IntVarP(&opt.contextLines, "context-lines", "c", opt.contextLines, "Number of context lines to show in diffs")
6281
pflag.BoolVarP(&opt.verbose, "verbose", "v", opt.verbose, "Enable more verbose output")
82+
pflag.BoolVarP(&opt.version, "version", "V", opt.version, "Show version info and exit immediately")
6383
pflag.Parse()
6484

85+
if opt.version {
86+
printVersion()
87+
return
88+
}
89+
6590
// setup logging
6691
var log = logrus.New()
6792
log.SetFormatter(&logrus.TextFormatter{

0 commit comments

Comments
 (0)