From f6f9c41ac01cadaa237ea9ff327c2d1f33486e6d Mon Sep 17 00:00:00 2001 From: Ivan Pusic <450140+ivpusic@users.noreply.github.com> Date: Mon, 30 Mar 2026 16:00:33 +0200 Subject: [PATCH 1/5] feat: add dune viz create command --- cli/root.go | 2 + cmd/visualization/create.go | 74 ++++++++++++++++++++++++++++++ cmd/visualization/visualization.go | 18 ++++++++ 3 files changed, 94 insertions(+) create mode 100644 cmd/visualization/create.go create mode 100644 cmd/visualization/visualization.go diff --git a/cli/root.go b/cli/root.go index ed16c0f..172c606 100644 --- a/cli/root.go +++ b/cli/root.go @@ -22,6 +22,7 @@ import ( "github.com/duneanalytics/cli/cmd/query" "github.com/duneanalytics/cli/cmd/sim" "github.com/duneanalytics/cli/cmd/usage" + "github.com/duneanalytics/cli/cmd/visualization" "github.com/duneanalytics/cli/cmd/whoami" "github.com/duneanalytics/cli/cmdutil" "github.com/duneanalytics/cli/tracking" @@ -121,6 +122,7 @@ func init() { rootCmd.AddCommand(usage.NewUsageCmd()) rootCmd.AddCommand(whoami.NewWhoAmICmd()) rootCmd.AddCommand(sim.NewSimCmd()) + rootCmd.AddCommand(visualization.NewVisualizationCmd()) } // Execute runs the root command via Fang. diff --git a/cmd/visualization/create.go b/cmd/visualization/create.go new file mode 100644 index 0000000..3a3499a --- /dev/null +++ b/cmd/visualization/create.go @@ -0,0 +1,74 @@ +package visualization + +import ( + "encoding/json" + "fmt" + + "github.com/duneanalytics/cli/cmdutil" + "github.com/duneanalytics/cli/output" + "github.com/duneanalytics/duneapi-client-go/models" + "github.com/spf13/cobra" +) + +func newCreateCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "create", + Short: "Create a new visualization on an existing query", + Long: "Create a visualization attached to an existing saved query.\n\n" + + "The visualization type must be one of: chart, table, counter, pivot,\n" + + "cohort, funnel, choropleth, sankey, sunburst_sequence, word_cloud.\n\n" + + "The --options flag accepts a JSON string of visualization-specific\n" + + "configuration (axes, series, formatting, etc.).\n\n" + + "Examples:\n" + + " dune viz create --query-id 12345 --name \"Token Volume\" --type chart\n" + + " dune viz create --query-id 12345 --name \"Summary\" --type counter --options '{\"column\":\"total\",\"row_num\":1}'\n" + + " dune viz create --query-id 12345 --name \"Results\" --type table -o json", + RunE: runCreate, + } + + cmd.Flags().Int("query-id", 0, "ID of the query to attach the visualization to (required)") + cmd.Flags().String("name", "", "visualization name, max 300 characters (required)") + cmd.Flags().String("type", "table", "visualization type: chart, table, counter, pivot, cohort, funnel, choropleth, sankey, sunburst_sequence, word_cloud") + cmd.Flags().String("description", "", "visualization description, max 1000 characters") + cmd.Flags().String("options", "{}", "JSON string of visualization options") + _ = cmd.MarkFlagRequired("query-id") + _ = cmd.MarkFlagRequired("name") + output.AddFormatFlag(cmd, "text") + + return cmd +} + +func runCreate(cmd *cobra.Command, _ []string) error { + client := cmdutil.ClientFromCmd(cmd) + + queryID, _ := cmd.Flags().GetInt("query-id") + name, _ := cmd.Flags().GetString("name") + vizType, _ := cmd.Flags().GetString("type") + description, _ := cmd.Flags().GetString("description") + optionsStr, _ := cmd.Flags().GetString("options") + + var options map[string]any + if err := json.Unmarshal([]byte(optionsStr), &options); err != nil { + return fmt.Errorf("invalid --options JSON: %w", err) + } + + resp, err := client.CreateVisualization(models.CreateVisualizationRequest{ + QueryID: queryID, + Name: name, + Type: vizType, + Description: description, + Options: options, + }) + if err != nil { + return err + } + + w := cmd.OutOrStdout() + switch output.FormatFromCmd(cmd) { + case output.FormatJSON: + return output.PrintJSON(w, resp) + default: + fmt.Fprintf(w, "Created visualization %d on query %d\n", resp.ID, queryID) + return nil + } +} diff --git a/cmd/visualization/visualization.go b/cmd/visualization/visualization.go new file mode 100644 index 0000000..df0603e --- /dev/null +++ b/cmd/visualization/visualization.go @@ -0,0 +1,18 @@ +package visualization + +import "github.com/spf13/cobra" + +func NewVisualizationCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "visualization", + Aliases: []string{"viz"}, + Short: "Create and manage Dune visualizations", + Long: "Create and manage visualizations on Dune queries.\n\n" + + "Visualizations are charts, tables, counters, and other visual representations\n" + + "of query results. Each visualization is attached to a saved query.", + } + + cmd.AddCommand(newCreateCmd()) + + return cmd +} From 30daea33d8f71d210c2fe9970326fb400dda85ae Mon Sep 17 00:00:00 2001 From: Ivan Pusic <450140+ivpusic@users.noreply.github.com> Date: Wed, 1 Apr 2026 12:01:43 +0200 Subject: [PATCH 2/5] chore: upgrade duneapi-client-go to v0.4.6 --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index a2afe95..7612842 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.25.6 require ( github.com/amplitude/analytics-go v1.3.0 github.com/charmbracelet/fang v0.4.4 - github.com/duneanalytics/duneapi-client-go v0.4.5 + github.com/duneanalytics/duneapi-client-go v0.4.6 github.com/modelcontextprotocol/go-sdk v1.4.0 github.com/spf13/cobra v1.10.2 github.com/stretchr/testify v1.11.1 diff --git a/go.sum b/go.sum index ae51a5e..e066223 100644 --- a/go.sum +++ b/go.sum @@ -31,8 +31,8 @@ github.com/clipperhouse/uax29/v2 v2.3.0/go.mod h1:Wn1g7MK6OoeDT0vL+Q0SQLDz/KpfsV github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/duneanalytics/duneapi-client-go v0.4.5 h1:LSSW2B2KG/OIXWuWHfVpOhsvuuR/lw4nJ7uyYE6NHB4= -github.com/duneanalytics/duneapi-client-go v0.4.5/go.mod h1:7pXXufWvR/Mh2KOehdyBaunJXmHI+pzjUmyQTQhJjdE= +github.com/duneanalytics/duneapi-client-go v0.4.6 h1:ZjW/H86Da6RY3K9rQFUV3pU1w8kTVlgSGH3k4v3VP7Q= +github.com/duneanalytics/duneapi-client-go v0.4.6/go.mod h1:7pXXufWvR/Mh2KOehdyBaunJXmHI+pzjUmyQTQhJjdE= github.com/golang-jwt/jwt/v5 v5.3.0 h1:pv4AsKCKKZuqlgs5sUmn4x8UlGa0kEVt/puTpKx9vvo= github.com/golang-jwt/jwt/v5 v5.3.0/go.mod h1:fxCRLWMO43lRc8nhHWY6LGqRcf+1gQWArsqaEUEa5bE= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= From f6b97b7960d49f9be95937d49b3311c074688b0f Mon Sep 17 00:00:00 2001 From: Ivan Pusic <450140+ivpusic@users.noreply.github.com> Date: Wed, 1 Apr 2026 12:08:51 +0200 Subject: [PATCH 3/5] docs updates --- cmd/visualization/create.go | 94 ++++++++++++++++++++++++++++++++----- 1 file changed, 81 insertions(+), 13 deletions(-) diff --git a/cmd/visualization/create.go b/cmd/visualization/create.go index 3a3499a..3c21716 100644 --- a/cmd/visualization/create.go +++ b/cmd/visualization/create.go @@ -14,25 +14,88 @@ func newCreateCmd() *cobra.Command { cmd := &cobra.Command{ Use: "create", Short: "Create a new visualization on an existing query", - Long: "Create a visualization attached to an existing saved query.\n\n" + - "The visualization type must be one of: chart, table, counter, pivot,\n" + - "cohort, funnel, choropleth, sankey, sunburst_sequence, word_cloud.\n\n" + - "The --options flag accepts a JSON string of visualization-specific\n" + - "configuration (axes, series, formatting, etc.).\n\n" + - "Examples:\n" + - " dune viz create --query-id 12345 --name \"Token Volume\" --type chart\n" + - " dune viz create --query-id 12345 --name \"Summary\" --type counter --options '{\"column\":\"total\",\"row_num\":1}'\n" + - " dune viz create --query-id 12345 --name \"Results\" --type table -o json", + Long: `Create a visualization attached to an existing saved query. + +IMPORTANT: The --options flag is required for a working visualization. Without +proper options, the visualization will fail to render. The options format depends +on the visualization type. + +Visualization types: chart, table, counter, pivot, cohort, funnel, choropleth, +sankey, sunburst_sequence, word_cloud. + +For chart type, set globalSeriesType to: column, line, area, scatter, or pie. + +COUNTER (simplest — shows a single number): + --type counter --options '{ + "counterColName": "", + "rowNumber": 1, + "stringDecimal": 0, + "stringPrefix": "", + "stringSuffix": "", + "counterLabel": "My Label", + "coloredPositiveValues": false, + "coloredNegativeValues": false + }' + +TABLE (displays query results as a table): + --type table --options '{ + "itemsPerPage": 25, + "columns": [ + {"name": "", "title": "Display Name", "type": "normal", + "alignContent": "left", "isHidden": false} + ] + }' + +COLUMN/LINE/AREA/SCATTER CHART: + --type chart --options '{ + "globalSeriesType": "line", + "sortX": true, + "legend": {"enabled": true}, + "series": {"stacking": null}, + "xAxis": {"title": {"text": "Date"}}, + "yAxis": [{"title": {"text": "Value"}}], + "columnMapping": {"": "x", "": "y"}, + "seriesOptions": { + "": {"type": "line", "yAxis": 0, "zIndex": 0} + } + }' + +PIE CHART: + --type chart --options '{ + "globalSeriesType": "pie", + "sortX": true, + "showDataLabels": true, + "columnMapping": {"": "x", "": "y"}, + "seriesOptions": { + "": {"type": "pie", "yAxis": 0, "zIndex": 0} + } + }' + +Column names in options must match actual query result columns exactly. + +Examples: + # Counter showing row count + dune viz create --query-id 12345 --name "Total Count" --type counter \ + --options '{"counterColName":"count","rowNumber":1,"stringDecimal":0}' + + # Line chart of daily volume + dune viz create --query-id 12345 --name "Daily Volume" --type chart \ + --options '{"globalSeriesType":"line","sortX":true,"columnMapping":{"day":"x","volume":"y"},"seriesOptions":{"volume":{"type":"line","yAxis":0,"zIndex":0}},"xAxis":{"title":{"text":"Day"}},"yAxis":[{"title":{"text":"Volume"}}],"legend":{"enabled":true},"series":{"stacking":null}}' + + # Simple table + dune viz create --query-id 12345 --name "Results" --type table \ + --options '{"itemsPerPage":25,"columns":[{"name":"address","title":"Address","type":"normal","alignContent":"left","isHidden":false},{"name":"balance","title":"Balance","type":"normal","alignContent":"right","isHidden":false}]}'`, RunE: runCreate, } cmd.Flags().Int("query-id", 0, "ID of the query to attach the visualization to (required)") cmd.Flags().String("name", "", "visualization name, max 300 characters (required)") - cmd.Flags().String("type", "table", "visualization type: chart, table, counter, pivot, cohort, funnel, choropleth, sankey, sunburst_sequence, word_cloud") + cmd.Flags().String("type", "table", "visualization type: chart, table, counter") cmd.Flags().String("description", "", "visualization description, max 1000 characters") - cmd.Flags().String("options", "{}", "JSON string of visualization options") + cmd.Flags().String("options", "", `visualization options JSON (required for working visualizations, see --help for format per type)`) _ = cmd.MarkFlagRequired("query-id") _ = cmd.MarkFlagRequired("name") + _ = cmd.MarkFlagRequired("options") output.AddFormatFlag(cmd, "text") return cmd @@ -63,12 +126,17 @@ func runCreate(cmd *cobra.Command, _ []string) error { return err } + url := fmt.Sprintf("https://dune.com/embeds/%d/%d", queryID, resp.ID) + w := cmd.OutOrStdout() switch output.FormatFromCmd(cmd) { case output.FormatJSON: - return output.PrintJSON(w, resp) + return output.PrintJSON(w, map[string]any{ + "id": resp.ID, + "url": url, + }) default: - fmt.Fprintf(w, "Created visualization %d on query %d\n", resp.ID, queryID) + fmt.Fprintf(w, "Created visualization %d on query %d\n%s\n", resp.ID, queryID, url) return nil } } From a1333945a1e311e940fe5f4bd680be71cca3d73b Mon Sep 17 00:00:00 2001 From: Ivan Pusic <450140+ivpusic@users.noreply.github.com> Date: Wed, 1 Apr 2026 12:42:06 +0200 Subject: [PATCH 4/5] docs: note that visualizations require non-temp queries --- cmd/visualization/create.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cmd/visualization/create.go b/cmd/visualization/create.go index 3c21716..dc69ce1 100644 --- a/cmd/visualization/create.go +++ b/cmd/visualization/create.go @@ -16,9 +16,12 @@ func newCreateCmd() *cobra.Command { Short: "Create a new visualization on an existing query", Long: `Create a visualization attached to an existing saved query. -IMPORTANT: The --options flag is required for a working visualization. Without -proper options, the visualization will fail to render. The options format depends -on the visualization type. +IMPORTANT: Visualizations can only be attached to saved (non-temporary) queries. +If you created the query with --temp, you must recreate it without --temp first. + +The --options flag is required for a working visualization. Without proper options, +the visualization will fail to render. The options format depends on the +visualization type. Visualization types: chart, table, counter, pivot, cohort, funnel, choropleth, sankey, sunburst_sequence, word_cloud. From 1435493f34897dd5e92cbe09ed6bd63fcc46e30c Mon Sep 17 00:00:00 2001 From: Ivan Pusic <450140+ivpusic@users.noreply.github.com> Date: Wed, 1 Apr 2026 13:19:55 +0200 Subject: [PATCH 5/5] docs: list all 10 visualization types in --type flag help --- cmd/visualization/create.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/visualization/create.go b/cmd/visualization/create.go index dc69ce1..df3e58c 100644 --- a/cmd/visualization/create.go +++ b/cmd/visualization/create.go @@ -93,7 +93,7 @@ Examples: cmd.Flags().Int("query-id", 0, "ID of the query to attach the visualization to (required)") cmd.Flags().String("name", "", "visualization name, max 300 characters (required)") - cmd.Flags().String("type", "table", "visualization type: chart, table, counter") + cmd.Flags().String("type", "table", "visualization type: chart, table, counter, pivot, cohort, funnel, choropleth, sankey, sunburst_sequence, word_cloud") cmd.Flags().String("description", "", "visualization description, max 1000 characters") cmd.Flags().String("options", "", `visualization options JSON (required for working visualizations, see --help for format per type)`) _ = cmd.MarkFlagRequired("query-id")