Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add version cmd #77

Merged
merged 1 commit into from
May 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Version := $(shell git describe --tags --dirty)
GitCommit := $(shell git rev-parse HEAD)
LDFLAGS := "-X main.Version=$(Version) -X main.GitCommit=$(GitCommit)"

build:
go build -o bin/vals ./cmd/vals
go build -ldflags $(LDFLAGS) -o bin/vals ./cmd/vals

install: build
mv bin/vals ~/bin/
17 changes: 16 additions & 1 deletion cmd/vals/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@ import (
"encoding/json"
"flag"
"fmt"
"os"

"github.com/variantdev/vals"
"gopkg.in/yaml.v3"
"os"
)

var (
Version string
GitCommit string
)

func flagUsage() {
Expand All @@ -22,6 +28,7 @@ Available Commands:
exec Populates the environment variables and executes the command
env Renders environment variables to be consumed by eval or a tool like direnv
ksdecode Decode YAML document(s) by converting Secret resources' "data" to "stringData" for use with "vals eval"
version Print vals version

Use "vals [command] --help" for more infomation about a command
`
Expand Down Expand Up @@ -57,6 +64,7 @@ func main() {
CmdExec := "exec"
CmdEnv := "env"
CmdKsDecode := "ksdecode"
CmdVersion := "version"

if len(os.Args) == 1 {
flag.Usage()
Expand Down Expand Up @@ -153,6 +161,13 @@ func main() {
fmt.Println("---")
}
}
case CmdVersion:
if len(Version) == 0 {
fmt.Println("Version: dev")
} else {
fmt.Println("Version:", Version)
}
fmt.Println("Git Commit:", GitCommit)
default:
flag.Usage()
}
Expand Down