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

feat(version): Adding app version command #11

Merged
merged 2 commits into from
Mar 22, 2024
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
10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
# 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
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
Expand Down
File renamed without changes.
46 changes: 46 additions & 0 deletions cmd/schema/cmd_version.go
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions cmd/schema/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func main() {
subcommands.Register(subcommands.FlagsCommand(), "")
subcommands.Register(subcommands.CommandsCommand(), "")

subcommands.Register(new(versionCmd), "")
subcommands.Register(new(generateCmd), "")

flag.Parse()
Expand Down
Loading