Explorar o código

Merge pull request #1118 from gtardif/metrics_not_send_if_cli_backend

Do not send metrics if executed as CLI backend
Guillaume Tardif %!s(int64=4) %!d(string=hai) anos
pai
achega
e658e1e531
Modificáronse 1 ficheiros con 9 adicións e 0 borrados
  1. 9 0
      metrics/metrics.go

+ 9 - 0
metrics/metrics.go

@@ -17,6 +17,7 @@
 package metrics
 package metrics
 
 
 import (
 import (
+	"os"
 	"strings"
 	"strings"
 
 
 	"github.com/docker/compose-cli/utils"
 	"github.com/docker/compose-cli/utils"
@@ -24,6 +25,9 @@ import (
 
 
 // Track sends the tracking analytics to Docker Desktop
 // Track sends the tracking analytics to Docker Desktop
 func Track(context string, args []string, status string) {
 func Track(context string, args []string, status string) {
+	if isInvokedAsCliBackend() {
+		return
+	}
 	command := GetCommand(args)
 	command := GetCommand(args)
 	if command != "" {
 	if command != "" {
 		c := NewClient()
 		c := NewClient()
@@ -36,6 +40,11 @@ func Track(context string, args []string, status string) {
 	}
 	}
 }
 }
 
 
+func isInvokedAsCliBackend() bool {
+	executable := os.Args[0]
+	return strings.HasSuffix(executable, "-backend")
+}
+
 func isCommand(word string) bool {
 func isCommand(word string) bool {
 	return utils.StringContains(commands, word) || isManagementCommand(word)
 	return utils.StringContains(commands, word) || isManagementCommand(word)
 }
 }