From 1a46648907c4ab9ca1aaa463234d3eff16a0f511 Mon Sep 17 00:00:00 2001 From: Jacob Brewer Date: Fri, 22 Mar 2024 08:38:06 +0000 Subject: [PATCH 1/2] Adding app version command --- Makefile | 6 ++- cmd/schema/{generate.go => cmd_generate.go} | 0 cmd/schema/cmd_version.go | 46 +++++++++++++++++++++ cmd/schema/main.go | 1 + 4 files changed, 52 insertions(+), 1 deletion(-) rename cmd/schema/{generate.go => cmd_generate.go} (100%) create mode 100644 cmd/schema/cmd_version.go diff --git a/Makefile b/Makefile index 8ee0957..7194d88 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,10 @@ +# Define variables +hash = $(shell git rev-parse --short HEAD) +DATE = $(shell date -u +'%Y-%m-%dT%H:%M:%SZ') + linux: clean @echo "Building for linux" - GOOS=linux GOARCH=amd64 go build -o bin/linux ./cmd/schema + GOOS=linux GOARCH=amd64 go build -o bin/linux -ldflags '-X main.Commit=$(hash) -X main.Date=$(DATE)' ./cmd/schema windows: clean @echo "Building for windows" GOOS=windows GOARCH=amd64 go build -o bin/windows ./cmd/schema diff --git a/cmd/schema/generate.go b/cmd/schema/cmd_generate.go similarity index 100% rename from cmd/schema/generate.go rename to cmd/schema/cmd_generate.go diff --git a/cmd/schema/cmd_version.go b/cmd/schema/cmd_version.go new file mode 100644 index 0000000..73969a9 --- /dev/null +++ b/cmd/schema/cmd_version.go @@ -0,0 +1,46 @@ +package main + +import ( + "context" + "flag" + "fmt" + "runtime" + + "github.com/google/subcommands" +) + +// Set at linking time +var ( + Commit string + Date string +) + +type versionCmd struct{} + +func (v versionCmd) Name() string { + return "version" +} + +func (v versionCmd) Synopsis() string { + return "Print application version information and exit" +} + +func (v versionCmd) Usage() string { + return `version: + Print application version information and exit. +` +} + +func (v versionCmd) SetFlags(f *flag.FlagSet) {} + +func (v versionCmd) Execute(_ context.Context, _ *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus { + fmt.Printf( + "Commit: %s\nRuntime: %s %s/%s\nDate: %s\n", + Commit, + runtime.Version(), + runtime.GOOS, + runtime.GOARCH, + Date, + ) + return subcommands.ExitSuccess +} diff --git a/cmd/schema/main.go b/cmd/schema/main.go index 4fc31bc..8de30bb 100644 --- a/cmd/schema/main.go +++ b/cmd/schema/main.go @@ -16,6 +16,7 @@ func main() { subcommands.Register(subcommands.FlagsCommand(), "") subcommands.Register(subcommands.CommandsCommand(), "") + subcommands.Register(new(versionCmd), "") subcommands.Register(new(generateCmd), "") flag.Parse() From 4a5baa74c2820a1dbada4df7067766320c0798b7 Mon Sep 17 00:00:00 2001 From: Jacob Brewer Date: Fri, 22 Mar 2024 08:40:12 +0000 Subject: [PATCH 2/2] Adding debug info for windows and mac --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 7194d88..de261e2 100644 --- a/Makefile +++ b/Makefile @@ -7,10 +7,10 @@ linux: clean GOOS=linux GOARCH=amd64 go build -o bin/linux -ldflags '-X main.Commit=$(hash) -X main.Date=$(DATE)' ./cmd/schema windows: clean @echo "Building for windows" - GOOS=windows GOARCH=amd64 go build -o bin/windows ./cmd/schema + GOOS=windows GOARCH=amd64 go build -o bin/windows -ldflags '-X main.Commit=$(hash) -X main.Date=$(DATE)' ./cmd/schema mac: clean @echo "Building for mac" - GOOS=darwin GOARCH=amd64 go build -o bin/mac ./cmd/schema + GOOS=darwin GOARCH=amd64 go build -o bin/mac -ldflags '-X main.Commit=$(hash) -X main.Date=$(DATE)' ./cmd/schema clean: @echo "Cleaning up" # Remove the bin directory