@@ -61,6 +61,7 @@ import (
61
61
)
62
62
63
63
var (
64
+ metricsClient metrics.Client
64
65
contextAgnosticCommands = map [string ]struct {}{
65
66
"context" : {},
66
67
"login" : {},
@@ -86,6 +87,12 @@ func init() {
86
87
if err := os .Setenv ("PATH" , appendPaths (os .Getenv ("PATH" ), path )); err != nil {
87
88
panic (err )
88
89
}
90
+
91
+ metricsClient = metrics .NewClient ()
92
+ metricsClient .WithCliVersionFunc (func () string {
93
+ return mobycli .CliVersion ()
94
+ })
95
+
89
96
// Seed random
90
97
rand .Seed (time .Now ().UnixNano ())
91
98
}
@@ -249,7 +256,7 @@ func main() {
249
256
if err = root .ExecuteContext (ctx ); err != nil {
250
257
handleError (ctx , err , ctype , currentContext , cc , root )
251
258
}
252
- metrics .Track (ctype , os .Args [1 :], compose .SuccessStatus )
259
+ metricsClient .Track (ctype , os .Args [1 :], compose .SuccessStatus )
253
260
}
254
261
255
262
func customizeCliForACI (command * cobra.Command , proxy * api.ServiceProxy ) {
@@ -271,7 +278,7 @@ func customizeCliForACI(command *cobra.Command, proxy *api.ServiceProxy) {
271
278
func handleError (ctx context.Context , err error , ctype string , currentContext string , cc * store.DockerContext , root * cobra.Command ) {
272
279
// if user canceled request, simply exit without any error message
273
280
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 )
275
282
os .Exit (130 )
276
283
}
277
284
if ctype == store .AwsContextType {
@@ -293,7 +300,7 @@ $ docker context create %s <name>`, cc.Type(), store.EcsContextType), ctype)
293
300
294
301
func exit (ctx string , err error , ctype string ) {
295
302
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 )
297
304
os .Exit (exit .StatusCode )
298
305
}
299
306
@@ -308,7 +315,7 @@ func exit(ctx string, err error, ctype string) {
308
315
metricsStatus = compose .CommandSyntaxFailure .MetricsStatus
309
316
exitCode = compose .CommandSyntaxFailure .ExitCode
310
317
}
311
- metrics .Track (ctype , os .Args [1 :], metricsStatus )
318
+ metricsClient .Track (ctype , os .Args [1 :], metricsStatus )
312
319
313
320
if errors .Is (err , api .ErrLoginRequired ) {
314
321
fmt .Fprintln (os .Stderr , err )
@@ -343,7 +350,7 @@ func checkIfUnknownCommandExistInDefaultContext(err error, currentContext string
343
350
344
351
if mobycli .IsDefaultContextCommand (dockerCommand ) {
345
352
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 )
347
354
os .Exit (1 )
348
355
}
349
356
}
0 commit comments