From 6a28b67554c61af5bcbd5a7fcd66c1ea73072dd6 Mon Sep 17 00:00:00 2001 From: Ivan Pusic <450140+ivpusic@users.noreply.github.com> Date: Fri, 6 Mar 2026 11:10:42 +0100 Subject: [PATCH 1/2] Versioning improvements --- cli/root.go | 6 ++-- cmd/dataset/search.go | 2 +- cmd/docs/search.go | 4 +-- cmd/main.go | 64 +++++++++++++++++++++++++++++++++++++++---- cmd/query/archive.go | 4 +-- cmd/query/create.go | 2 +- cmd/query/get.go | 4 +-- cmd/query/run.go | 5 ++-- cmd/query/run_sql.go | 4 +-- cmd/query/update.go | 4 +-- cmd/usage/usage.go | 2 +- makefile | 15 ++++++++-- output/output.go | 1 - 13 files changed, 91 insertions(+), 26 deletions(-) diff --git a/cli/root.go b/cli/root.go index ff0dc95..63e8f92 100644 --- a/cli/root.go +++ b/cli/root.go @@ -78,9 +78,11 @@ func init() { // Execute runs the root command via Fang. func Execute(version, commit, date string) { - rootCmd.Version = fmt.Sprintf("%s (commit: %s, built: %s)", version, commit, date) + versionStr := fmt.Sprintf("%s (commit: %s, built: %s)", version, commit, date) - if err := fang.Execute(context.Background(), rootCmd); err != nil { + if err := fang.Execute(context.Background(), rootCmd, + fang.WithVersion(versionStr), + ); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } diff --git a/cmd/dataset/search.go b/cmd/dataset/search.go index 4cd61c5..e5cefd5 100644 --- a/cmd/dataset/search.go +++ b/cmd/dataset/search.go @@ -19,7 +19,7 @@ func newSearchCmd() *cobra.Command { "Filter by category (canonical for chain primitives, decoded for ABI-level\n" + "events/calls, spell for curated datasets, community for user-contributed),\n" + "by blockchain, schema, dataset type, or ownership scope.", - RunE: runSearch, + RunE: runSearch, } cmd.Flags().String("query", "", "natural-language search intent or entity hints (e.g. 'uniswap v3 swaps'); use '*' to browse without keyword bias") diff --git a/cmd/docs/search.go b/cmd/docs/search.go index 4067f7b..59d6ae8 100644 --- a/cmd/docs/search.go +++ b/cmd/docs/search.go @@ -13,8 +13,8 @@ const defaultMCPEndpoint = "https://docs.dune.com/mcp" func newSearchCmd() *cobra.Command { cmd := &cobra.Command{ - Use: "search", - Short: "Search the Dune documentation for guides, API references, and code examples", + Use: "search", + Short: "Search the Dune documentation for guides, API references, and code examples", Long: "Search across all Dune documentation pages including guides, API references,\n" + "DuneSQL syntax, and code examples. Does not require authentication.", Annotations: map[string]string{"skipAuth": "true"}, diff --git a/cmd/main.go b/cmd/main.go index 048be8e..214a53d 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -1,14 +1,68 @@ package main -import "github.com/duneanalytics/cli/cli" +import ( + "runtime/debug" + "strings" -// Set by GoReleaser via ldflags. + "github.com/duneanalytics/cli/cli" +) + +// Set by GoReleaser or Makefile via ldflags. var ( - version = "dev" - commit = "none" - date = "unknown" + version = "" + commit = "" + date = "" ) func main() { + resolveVersion() cli.Execute(version, commit, date) } + +// resolveVersion fills in version/commit/date from Go build info +// when they haven't been set via ldflags (i.e. plain go build / go install). +func resolveVersion() { + info, ok := debug.ReadBuildInfo() + if !ok { + setDefaults() + return + } + + // For go install ...@vX.Y.Z, the module version is clean (e.g. "v0.0.2"). + // For local builds it is "(devel)" — not useful. + if version == "" { + if v := info.Main.Version; v != "" && v != "(devel)" && !strings.Contains(v, "-") { + version = strings.TrimPrefix(v, "v") + } + } + + for _, s := range info.Settings { + switch s.Key { + case "vcs.revision": + if commit == "" && s.Value != "" { + commit = s.Value + if len(commit) > 12 { + commit = commit[:12] + } + } + case "vcs.time": + if date == "" && s.Value != "" { + date = s.Value + } + } + } + + setDefaults() +} + +func setDefaults() { + if version == "" { + version = "dev" + } + if commit == "" { + commit = "unknown" + } + if date == "" { + date = "unknown" + } +} diff --git a/cmd/query/archive.go b/cmd/query/archive.go index ed61a0a..7c4c5e2 100644 --- a/cmd/query/archive.go +++ b/cmd/query/archive.go @@ -15,8 +15,8 @@ func newArchiveCmd() *cobra.Command { Long: "Mark a Dune query as archived. Archived queries are hidden from the library\n" + "but can still be retrieved by ID. You must own the query or have edit access\n" + "via team membership.", - Args: cobra.ExactArgs(1), - RunE: runArchive, + Args: cobra.ExactArgs(1), + RunE: runArchive, } output.AddFormatFlag(cmd, "text") diff --git a/cmd/query/create.go b/cmd/query/create.go index 31a5ae4..d7ab629 100644 --- a/cmd/query/create.go +++ b/cmd/query/create.go @@ -18,7 +18,7 @@ func newCreateCmd() *cobra.Command { "known partition columns, include a WHERE filter on those columns\n" + "(e.g. WHERE block_date >= CURRENT_DATE - INTERVAL '7' DAY) to enable\n" + "partition pruning and reduce query cost.", - RunE: runCreate, + RunE: runCreate, } cmd.Flags().String("name", "", "human-readable query title, max 600 characters (required)") diff --git a/cmd/query/get.go b/cmd/query/get.go index 6b780bc..aea6f7d 100644 --- a/cmd/query/get.go +++ b/cmd/query/get.go @@ -15,8 +15,8 @@ func newGetCmd() *cobra.Command { Short: "Fetch a saved Dune query by ID, including SQL and metadata", Long: "Retrieve SQL, metadata, owner, privacy flags, tags, and execution state for\n" + "an existing Dune query. Only queries visible to the authenticated user are returned.", - Args: cobra.ExactArgs(1), - RunE: runGet, + Args: cobra.ExactArgs(1), + RunE: runGet, } output.AddFormatFlag(cmd, "text") diff --git a/cmd/query/run.go b/cmd/query/run.go index 19be0e7..274e147 100644 --- a/cmd/query/run.go +++ b/cmd/query/run.go @@ -19,8 +19,8 @@ func newRunCmd() *cobra.Command { "the execution and exit immediately with just the execution ID.\n\n" + "Credits are consumed based on actual compute resources used. Use --performance\n" + "to select the engine size (medium or large).", - Args: cobra.ExactArgs(1), - RunE: runRun, + Args: cobra.ExactArgs(1), + RunE: runRun, } cmd.Flags().StringArray("param", nil, "typed query parameter in key=value format (repeatable); numbers are stringified, datetimes use YYYY-MM-DD HH:mm:ss") @@ -106,4 +106,3 @@ func parseParams(raw []string) (map[string]any, error) { } return params, nil } - diff --git a/cmd/query/run_sql.go b/cmd/query/run_sql.go index ed18752..d30f345 100644 --- a/cmd/query/run_sql.go +++ b/cmd/query/run_sql.go @@ -15,8 +15,8 @@ func newRunSQLCmd() *cobra.Command { "query on Dune. By default, waits for completion and displays result rows.\n\n" + "Use --no-wait to submit the execution and exit immediately with just the\n" + "execution ID. Credits are consumed based on actual compute resources used.", - Args: cobra.NoArgs, - RunE: runRunSQL, + Args: cobra.NoArgs, + RunE: runRunSQL, } cmd.Flags().String("sql", "", "the SQL query text in DuneSQL dialect (required)") diff --git a/cmd/query/update.go b/cmd/query/update.go index 3257fca..976d88e 100644 --- a/cmd/query/update.go +++ b/cmd/query/update.go @@ -17,8 +17,8 @@ func newUpdateCmd() *cobra.Command { "Only supply the flags you want to change; unchanged fields are preserved.\n\n" + "The update uses optimistic locking — if someone else edited the query\n" + "concurrently, you'll get a conflict error.", - Args: cobra.ExactArgs(1), - RunE: runUpdate, + Args: cobra.ExactArgs(1), + RunE: runUpdate, } cmd.Flags().String("name", "", "new title for the query, max 600 characters") diff --git a/cmd/usage/usage.go b/cmd/usage/usage.go index b061237..e333134 100644 --- a/cmd/usage/usage.go +++ b/cmd/usage/usage.go @@ -17,7 +17,7 @@ func NewUsageCmd() *cobra.Command { Short: "Get credit and resource usage for the authenticated Dune account", Long: "Show current-period credit usage, storage consumption, and billing period\n" + "boundaries for the authenticated user or team. Optionally filter by date range.", - RunE: runUsage, + RunE: runUsage, } cmd.Flags().String("start-date", "", "filter usage from this date (YYYY-MM-DD format)") diff --git a/makefile b/makefile index 6947832..ad33d02 100644 --- a/makefile +++ b/makefile @@ -1,4 +1,12 @@ -.PHONY: all setup build lint test +.PHONY: all setup build lint test install + +VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null | sed 's/^v//') +COMMIT ?= $(shell git rev-parse --short=12 HEAD 2>/dev/null || echo "unknown") +DATE ?= $(shell date -u '+%Y-%m-%dT%H:%M:%SZ') +LDFLAGS = -s -w \ + -X main.version=$(VERSION) \ + -X main.commit=$(COMMIT) \ + -X main.date=$(DATE) all: lint test build @@ -6,10 +14,13 @@ setup: bin/golangci-lint go mod download dune-cli: lint - go build -o dune-cli cmd/main.go + go build -ldflags '$(LDFLAGS)' -o dune-cli ./cmd build: dune-cli +install: + go install -ldflags '$(LDFLAGS)' ./cmd + bin: mkdir -p bin diff --git a/output/output.go b/output/output.go index f41fb6e..e726043 100644 --- a/output/output.go +++ b/output/output.go @@ -76,4 +76,3 @@ func FormatBytes(b int64) string { return fmt.Sprintf("%d B", b) } } - From 474723027d0d20ca25ab153cc48fb7f501108cb9 Mon Sep 17 00:00:00 2001 From: Ivan Pusic <450140+ivpusic@users.noreply.github.com> Date: Fri, 6 Mar 2026 11:38:47 +0100 Subject: [PATCH 2/2] fix install script --- makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makefile b/makefile index ad33d02..10c13a4 100644 --- a/makefile +++ b/makefile @@ -19,7 +19,7 @@ dune-cli: lint build: dune-cli install: - go install -ldflags '$(LDFLAGS)' ./cmd + go build -ldflags '$(LDFLAGS)' -o $(shell go env GOPATH)/bin/dune ./cmd bin: mkdir -p bin