From e854bbb3e179ac37ed140366a417e9f01a0422b7 Mon Sep 17 00:00:00 2001 From: Connor Edwards <38229097+cedws@users.noreply.github.com> Date: Fri, 25 Apr 2025 19:55:37 +0900 Subject: [PATCH] feat: add version flag to main cmd --- .goreleaser.yaml | 4 ++++ cmd/uncloud/main.go | 2 ++ internal/version/version.go | 7 +++++++ 3 files changed, 13 insertions(+) create mode 100644 internal/version/version.go diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 71afd9de..40da917d 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -24,6 +24,8 @@ builds: goarch: - amd64 - arm64 + ldflags: + - -s -w -X github.com/psviderski/uncloud/internal/version.version={{ .Version }} - id: uncloudd main: ./cmd/uncloudd @@ -35,6 +37,8 @@ builds: goarch: - amd64 - arm64 + ldflags: + - -s -w -X github.com/psviderski/uncloud/internal/version.version={{ .Version }} archives: - id: uncloud diff --git a/cmd/uncloud/main.go b/cmd/uncloud/main.go index 1add1cc0..9640eb9d 100644 --- a/cmd/uncloud/main.go +++ b/cmd/uncloud/main.go @@ -15,6 +15,7 @@ import ( "github.com/psviderski/uncloud/internal/cli" "github.com/psviderski/uncloud/internal/cli/config" "github.com/psviderski/uncloud/internal/fs" + "github.com/psviderski/uncloud/internal/version" "github.com/spf13/cobra" ) @@ -28,6 +29,7 @@ func main() { cmd := &cobra.Command{ Use: "uncloud", Short: "A CLI tool for managing Uncloud resources such as clusters, machines, and services.", + Version: version.String(), SilenceUsage: true, SilenceErrors: true, PersistentPreRunE: func(cmd *cobra.Command, args []string) error { diff --git a/internal/version/version.go b/internal/version/version.go new file mode 100644 index 00000000..c05c1c24 --- /dev/null +++ b/internal/version/version.go @@ -0,0 +1,7 @@ +package version + +var version string + +func String() string { + return version +}