@@ -61,6 +61,7 @@ import (
6161)
6262
6363var (
64+ metricsClient metrics.Client
6465 contextAgnosticCommands = map [string ]struct {}{
6566 "context" : {},
6667 "login" : {},
@@ -86,6 +87,12 @@ func init() {
8687 if err := os .Setenv ("PATH" , appendPaths (os .Getenv ("PATH" ), path )); err != nil {
8788 panic (err )
8889 }
90+
91+ metricsClient = metrics .NewClient ()
92+ metricsClient .WithCliVersionFunc (func () string {
93+ return mobycli .CliVersion ()
94+ })
95+
8996 // Seed random
9097 rand .Seed (time .Now ().UnixNano ())
9198}
@@ -249,7 +256,7 @@ func main() {
249256 if err = root .ExecuteContext (ctx ); err != nil {
250257 handleError (ctx , err , ctype , currentContext , cc , root )
251258 }
252- metrics .Track (ctype , os .Args [1 :], compose .SuccessStatus )
259+ metricsClient .Track (ctype , os .Args [1 :], compose .SuccessStatus )
253260}
254261
255262func customizeCliForACI (command * cobra.Command , proxy * api.ServiceProxy ) {
@@ -271,7 +278,7 @@ func customizeCliForACI(command *cobra.Command, proxy *api.ServiceProxy) {
271278func handleError (ctx context.Context , err error , ctype string , currentContext string , cc * store.DockerContext , root * cobra.Command ) {
272279 // if user canceled request, simply exit without any error message
273280 if api .IsErrCanceled (err ) || errors .Is (ctx .Err (), context .Canceled ) {
274- metrics .Track (ctype , os .Args [1 :], compose .CanceledStatus )
281+ metricsClient .Track (ctype , os .Args [1 :], compose .CanceledStatus )
275282 os .Exit (130 )
276283 }
277284 if ctype == store .AwsContextType {
@@ -293,7 +300,7 @@ $ docker context create %s <name>`, cc.Type(), store.EcsContextType), ctype)
293300
294301func exit (ctx string , err error , ctype string ) {
295302 if exit , ok := err .(cli.StatusError ); ok {
296- metrics .Track (ctype , os .Args [1 :], compose .SuccessStatus )
303+ metricsClient .Track (ctype , os .Args [1 :], compose .SuccessStatus )
297304 os .Exit (exit .StatusCode )
298305 }
299306
@@ -308,7 +315,7 @@ func exit(ctx string, err error, ctype string) {
308315 metricsStatus = compose .CommandSyntaxFailure .MetricsStatus
309316 exitCode = compose .CommandSyntaxFailure .ExitCode
310317 }
311- metrics .Track (ctype , os .Args [1 :], metricsStatus )
318+ metricsClient .Track (ctype , os .Args [1 :], metricsStatus )
312319
313320 if errors .Is (err , api .ErrLoginRequired ) {
314321 fmt .Fprintln (os .Stderr , err )
@@ -343,7 +350,7 @@ func checkIfUnknownCommandExistInDefaultContext(err error, currentContext string
343350
344351 if mobycli .IsDefaultContextCommand (dockerCommand ) {
345352 fmt .Fprintf (os .Stderr , "Command %q not available in current context (%s), you can use the \" default\" context to run this command\n " , dockerCommand , currentContext )
346- metrics .Track (contextType , os .Args [1 :], compose .FailureStatus )
353+ metricsClient .Track (contextType , os .Args [1 :], compose .FailureStatus )
347354 os .Exit (1 )
348355 }
349356 }
0 commit comments