@@ -8,6 +8,11 @@ import (
88 "time"
99
1010 "github.com/charmbracelet/fang"
11+ "github.com/spf13/cobra"
12+
13+ "github.com/duneanalytics/duneapi-client-go/config"
14+ "github.com/duneanalytics/duneapi-client-go/dune"
15+
1116 "github.com/duneanalytics/cli/authconfig"
1217 "github.com/duneanalytics/cli/cmd/auth"
1318 duneconfig "github.com/duneanalytics/cli/cmd/config"
@@ -18,9 +23,6 @@ import (
1823 "github.com/duneanalytics/cli/cmd/usage"
1924 "github.com/duneanalytics/cli/cmdutil"
2025 "github.com/duneanalytics/cli/tracking"
21- "github.com/duneanalytics/duneapi-client-go/config"
22- "github.com/duneanalytics/duneapi-client-go/dune"
23- "github.com/spf13/cobra"
2426)
2527
2628var apiKeyFlag string
@@ -126,9 +128,40 @@ func Execute(version, commit, date, amplitudeKey string) {
126128 if err := fang .Execute (rootCmd .Context (), rootCmd ,
127129 fang .WithVersion (versionStr ),
128130 ); err != nil {
129- tracker .Track ("unknown" , tracking .StatusError , err .Error (), 0 )
131+ // Build best-effort command path from os.Args (strip flags).
132+ commandPath := commandPathFromArgs (os .Args )
133+ tracker .Track (commandPath , tracking .StatusError , err .Error (), 0 )
134+ // Flush the event before exiting — os.Exit does not run deferred funcs,
135+ // so defer tracker.Shutdown() above would never fire.
136+ tracker .Shutdown ()
130137
131138 fmt .Fprintln (os .Stderr , err )
132139 os .Exit (1 )
133140 }
134141}
142+
143+ // commandPathFromArgs extracts the subcommand path from os.Args, skipping
144+ // the binary name, flags, and flag values so the tracked path is e.g.
145+ // "query list" even when invoked as "dune --api-key KEY query list --limit 10".
146+ func commandPathFromArgs (args []string ) string {
147+ var parts []string
148+ skipNext := false
149+ for _ , a := range args [1 :] { // skip binary name
150+ if skipNext {
151+ skipNext = false
152+ continue
153+ }
154+ if strings .HasPrefix (a , "-" ) {
155+ // --flag=value is self-contained; --flag value needs to skip the next arg.
156+ if ! strings .Contains (a , "=" ) {
157+ skipNext = true
158+ }
159+ continue
160+ }
161+ parts = append (parts , a )
162+ }
163+ if len (parts ) == 0 {
164+ return "unknown"
165+ }
166+ return strings .Join (parts , " " )
167+ }
0 commit comments