Skip to content

Commit 48fa83b

Browse files
committed
Add version support
1 parent 6a4e7f5 commit 48fa83b

File tree

4 files changed

+78
-8
lines changed

4 files changed

+78
-8
lines changed

Makefile

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,20 @@
33
# Default target
44
all: build
55

6+
# Variables for version injection
7+
BUILD_TIME := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
8+
GIT_COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
9+
LDFLAGS := -X sentire/internal/version.BuildTime=$(BUILD_TIME) -X sentire/internal/version.GitCommit=$(GIT_COMMIT)
10+
611
# Build the application
712
build:
813
@echo "Building sentire..."
9-
@go build -o sentire ./cmd/sentire
14+
@go build -ldflags="$(LDFLAGS)" -o sentire ./cmd/sentire
1015

1116
# Build with version information
1217
build-release:
1318
@echo "Building sentire with version info..."
14-
@go build -ldflags="-s -w" -o sentire ./cmd/sentire
19+
@go build -ldflags="$(LDFLAGS) -s -w" -o sentire ./cmd/sentire
1520

1621
# Run tests
1722
test:
@@ -56,10 +61,10 @@ install: build
5661
# Cross-compile for multiple platforms
5762
build-all:
5863
@echo "Building for multiple platforms..."
59-
@GOOS=linux GOARCH=amd64 go build -o sentire-linux-amd64 ./cmd/sentire
60-
@GOOS=darwin GOARCH=amd64 go build -o sentire-darwin-amd64 ./cmd/sentire
61-
@GOOS=darwin GOARCH=arm64 go build -o sentire-darwin-arm64 ./cmd/sentire
62-
@GOOS=windows GOARCH=amd64 go build -o sentire-windows-amd64.exe ./cmd/sentire
64+
@GOOS=linux GOARCH=amd64 go build -ldflags="$(LDFLAGS)" -o sentire-linux-amd64 ./cmd/sentire
65+
@GOOS=darwin GOARCH=amd64 go build -ldflags="$(LDFLAGS)" -o sentire-darwin-amd64 ./cmd/sentire
66+
@GOOS=darwin GOARCH=arm64 go build -ldflags="$(LDFLAGS)" -o sentire-darwin-arm64 ./cmd/sentire
67+
@GOOS=windows GOARCH=amd64 go build -ldflags="$(LDFLAGS)" -o sentire-windows-amd64.exe ./cmd/sentire
6368

6469
# Show help
6570
help:

internal/cli/root.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ import (
55
"os"
66

77
"github.com/spf13/cobra"
8+
"sentire/internal/version"
89
)
910

1011
var rootCmd = &cobra.Command{
11-
Use: "sentire",
12-
Short: "A command-line tool for the Sentry API",
12+
Use: "sentire",
13+
Short: "A command-line tool for the Sentry API",
14+
Version: version.Version,
1315
Long: `Sentire is a simple and user-friendly command-line interface for interacting with the Sentry API.
1416
It allows you to query events, issues, projects, and organizations directly from your terminal.
1517

internal/cli/version.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package cli
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/spf13/cobra"
7+
"sentire/internal/version"
8+
)
9+
10+
var versionCmd = &cobra.Command{
11+
Use: "version",
12+
Short: "Show version information",
13+
Long: "Display version, build time, and build information for sentire",
14+
Run: func(cmd *cobra.Command, args []string) {
15+
detailed, _ := cmd.Flags().GetBool("detailed")
16+
if detailed {
17+
fmt.Println(version.GetFullVersionInfo())
18+
} else {
19+
fmt.Println(version.GetVersionInfo())
20+
}
21+
},
22+
}
23+
24+
func init() {
25+
versionCmd.Flags().BoolP("detailed", "d", false, "Show detailed version information")
26+
rootCmd.AddCommand(versionCmd)
27+
}

internal/version/version.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package version
2+
3+
import (
4+
"fmt"
5+
"runtime"
6+
)
7+
8+
// Version is the current version of sentire
9+
const Version = "0.1.0"
10+
11+
// These variables will be set at build time via ldflags
12+
var (
13+
BuildTime = "unknown"
14+
GitCommit = "unknown"
15+
)
16+
17+
// GetVersionInfo returns formatted version information
18+
func GetVersionInfo() string {
19+
return fmt.Sprintf("sentire version %s", Version)
20+
}
21+
22+
// GetFullVersionInfo returns detailed version information
23+
func GetFullVersionInfo() string {
24+
return fmt.Sprintf(`sentire version %s
25+
Build time: %s
26+
Git commit: %s
27+
Go version: %s
28+
OS/Arch: %s/%s`,
29+
Version,
30+
BuildTime,
31+
GitCommit,
32+
runtime.Version(),
33+
runtime.GOOS,
34+
runtime.GOARCH,
35+
)
36+
}

0 commit comments

Comments
 (0)