diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7c9d4d3..9305954 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -2,7 +2,6 @@ name: goreleaser on: - pull_request: push: # run only against tags tags: diff --git a/Makefile b/Makefile index 2d64543..e0aa2bd 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,3 @@ .PHONY: build build: - go build -o out/shell-now ./cmd/shell-now/ + go build -ldflags "-X main.version=$(shell git describe --tags --always --dirty) -X main.commit=$(shell git rev-parse HEAD) -X main.buildTime=$(shell date -u +%Y-%m-%dT%H:%M:%SZ)" -o out/shell-now ./cmd/shell-now/ diff --git a/cmd/shell-now/main.go b/cmd/shell-now/main.go index f27ab9e..0739bdc 100644 --- a/cmd/shell-now/main.go +++ b/cmd/shell-now/main.go @@ -2,6 +2,7 @@ package main import ( "context" + "fmt" "log/slog" "os" "os/signal" @@ -11,6 +12,12 @@ import ( "github.com/strrl/shell-now/pkg" ) +var ( + version = "dev" + commit = "unknown" + buildTime = "unknown" +) + func main() { if os.Getenv("DEBUG") != "" { @@ -25,8 +32,9 @@ func main() { defer stop() rootCmd := &cobra.Command{ - Use: "shell-now", - Short: "Shell Now is a simple command-line tool to expose your local shell to the public internet.", + Use: "shell-now", + Short: "Shell Now is a simple command-line tool to expose your local shell to the public internet.", + Version: version, RunE: func(cmd *cobra.Command, args []string) error { return pkg.Bootstrap(ctx) }, @@ -93,6 +101,18 @@ PowerShell: } rootCmd.AddCommand(completionCmd) + // Add version command + versionCmd := &cobra.Command{ + Use: "version", + Short: "Print the version information of shell-now", + Run: func(cmd *cobra.Command, args []string) { + fmt.Printf("shell-now version %s\n", version) + fmt.Printf("git commit: %s\n", commit) + fmt.Printf("build time: %s\n", buildTime) + }, + } + rootCmd.AddCommand(versionCmd) + // Execute with context if err := rootCmd.ExecuteContext(ctx); err != nil { os.Exit(1)