Skip to content

Commit

Permalink
Add --version flag.
Browse files Browse the repository at this point in the history
  • Loading branch information
atombender committed Aug 10, 2020
1 parent 4673176 commit c2724f8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
19 changes: 19 additions & 0 deletions gen_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh

v=$(git tag --contains HEAD)
if [ "$v" = "" ]; then
echo "Cannot determine tag." >&2
exit 1
fi

v=$(echo "$v" | sed -Ee 's#^v(.*)#\1#')

cat <<END >version.go
// Code generated by gen_version.sh, DO NOT EDIT.
package main
//go:generate sh -c ./gen_version.sh
const version = "$v"
END
9 changes: 8 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"github.com/fatih/color"
"github.com/spf13/pflag"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/client-go/kubernetes"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
Expand All @@ -29,6 +29,7 @@ func main() {
raw bool
tmplString string
sinceStart bool
showVersion bool
includePatterns []*regexp.Regexp
excludePatternStrings []string
)
Expand All @@ -55,12 +56,18 @@ func main() {
flags.BoolVarP(&quiet, "quiet", "q", false, "Don't print events about new/deleted pods")
flags.BoolVarP(&sinceStart, "since-start", "s", false,
"Start reading log from the beginning of the container's lifetime.")
flags.BoolVarP(&showVersion, "version", "", false, "Show version.")

if err := flags.Parse(os.Args[1:]); err != nil {
fail(err.Error())
os.Exit(1)
}

if showVersion {
fmt.Printf("ktail %s\n", version)
os.Exit(0)
}

var excludePatterns []*regexp.Regexp
for _, p := range excludePatternStrings {
r, err := regexp.Compile(p)
Expand Down
7 changes: 7 additions & 0 deletions version.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c2724f8

Please sign in to comment.