Merge pull request #1118 from gtardif/metrics_not_send_if_cli_backend

Do not send metrics if executed as CLI backend
This commit is contained in:
Guillaume Tardif 2021-01-11 14:21:40 +01:00 committed by GitHub
commit e658e1e531
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 0 deletions

View File

@ -17,6 +17,7 @@
package metrics
import (
"os"
"strings"
"github.com/docker/compose-cli/utils"
@ -24,6 +25,9 @@ import (
// Track sends the tracking analytics to Docker Desktop
func Track(context string, args []string, status string) {
if isInvokedAsCliBackend() {
return
}
command := GetCommand(args)
if command != "" {
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 {
return utils.StringContains(commands, word) || isManagementCommand(word)
}