Skip to content

Commit

Permalink
add --version
Browse files Browse the repository at this point in the history
  • Loading branch information
xrstf committed Jul 24, 2023
1 parent a91b001 commit 16f5637
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 13 deletions.
4 changes: 3 additions & 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 All @@ -22,6 +22,8 @@ builds:
ignore:
- goos: darwin
goarch: '386'
- goos: freebsd
goarch: '386'
binary: '{{ .ProjectName }}'
archives:
- format: zip
Expand Down
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,18 @@ go install go.xrstf.de/stalk

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

## Examples
Expand Down
37 changes: 31 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package main

import (
"context"
"fmt"
"io"
"os"
"runtime"
"strings"
"sync"
"time"
Expand All @@ -24,6 +26,22 @@ import (
"k8s.io/client-go/tools/clientcmd"
)

// 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
namespaces []string
Expand All @@ -37,6 +55,7 @@ type options struct {
disableWordDiff bool
contextLines int
verbose bool
version bool
}

func main() {
Expand All @@ -49,19 +68,25 @@ func main() {
contextLines: 3,
}

pflag.StringVar(&opt.kubeconfig, "kubeconfig", opt.kubeconfig, "kubeconfig file to use (uses $KUBECONFIG by default)")
pflag.StringVar(&opt.kubeconfig, "kubeconfig", opt.kubeconfig, "Kubeconfig file to use (uses $KUBECONFIG by default)")
pflag.StringArrayVarP(&opt.namespaces, "namespace", "n", opt.namespaces, "Kubernetes namespace to watch resources in (supports glob expression) (can be given multiple times)")
pflag.StringVarP(&opt.labels, "labels", "l", opt.labels, "Label-selector as an alternative to specifying resource names")
pflag.BoolVar(&opt.hideManagedFields, "hide-managed", opt.hideManagedFields, "Do not show managed fields")
pflag.StringVarP(&opt.jsonPath, "jsonpath", "j", opt.jsonPath, "JSON path expression to transform the output (applied before the --show paths)")
pflag.StringArrayVarP(&opt.showPaths, "show", "s", opt.showPaths, "path expression to include in output (can be given multiple times) (applied before the --hide paths)")
pflag.StringArrayVarP(&opt.hidePaths, "hide", "h", opt.hidePaths, "path expression to hide in output (can be given multiple times)")
pflag.BoolVarP(&opt.showEmpty, "show-empty", "e", opt.showEmpty, "do not hide changes which would produce no diff because of --hide/--show/--jsonpath")
pflag.BoolVarP(&opt.disableWordDiff, "diff-by-line", "w", opt.disableWordDiff, "diff entire lines and do not highlight changes within words")
pflag.IntVarP(&opt.contextLines, "context-lines", "c", opt.contextLines, "number of context lines to show in diffs")
pflag.StringArrayVarP(&opt.showPaths, "show", "s", opt.showPaths, "Path expression to include in output (can be given multiple times) (applied before the --hide paths)")
pflag.StringArrayVarP(&opt.hidePaths, "hide", "h", opt.hidePaths, "Path expression to hide in output (can be given multiple times)")
pflag.BoolVarP(&opt.showEmpty, "show-empty", "e", opt.showEmpty, "Do not hide changes which would produce no diff because of --hide/--show/--jsonpath")
pflag.BoolVarP(&opt.disableWordDiff, "diff-by-line", "w", opt.disableWordDiff, "Compare entire lines and do not highlight changes within words")
pflag.IntVarP(&opt.contextLines, "context-lines", "c", opt.contextLines, "Number of context lines to show in diffs")
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
var log = logrus.New()
log.SetFormatter(&logrus.TextFormatter{
Expand Down

0 comments on commit 16f5637

Please sign in to comment.