From 2702d10f81400af73755b1309e0bd23d875829e6 Mon Sep 17 00:00:00 2001 From: Tony Worm Date: Wed, 13 May 2020 19:29:36 -0600 Subject: [PATCH] upstream ga fixes --- .hof/Cli/cmd/mvs/cmd/convert.go | 2 +- .hof/Cli/cmd/mvs/cmd/graph.go | 2 +- .hof/Cli/cmd/mvs/cmd/hack.go | 2 +- .hof/Cli/cmd/mvs/cmd/info.go | 2 +- .hof/Cli/cmd/mvs/cmd/init.go | 2 +- .hof/Cli/cmd/mvs/cmd/root.go | 7 ++---- .hof/Cli/cmd/mvs/cmd/status.go | 2 +- .hof/Cli/cmd/mvs/cmd/tidy.go | 2 +- .hof/Cli/cmd/mvs/cmd/vendor.go | 2 +- .hof/Cli/cmd/mvs/cmd/verify.go | 2 +- .hof/Cli/cmd/mvs/ga/ga.go | 38 +++++++++++++++++++++------------ cmd/mvs/cmd/convert.go | 2 +- cmd/mvs/cmd/graph.go | 2 +- cmd/mvs/cmd/hack.go | 2 +- cmd/mvs/cmd/info.go | 2 +- cmd/mvs/cmd/init.go | 2 +- cmd/mvs/cmd/root.go | 7 ++---- cmd/mvs/cmd/status.go | 2 +- cmd/mvs/cmd/tidy.go | 2 +- cmd/mvs/cmd/vendor.go | 2 +- cmd/mvs/cmd/verify.go | 2 +- cmd/mvs/ga/ga.go | 38 +++++++++++++++++++++------------ cue.mods | 2 +- cue.sums | 2 ++ go.mod | 2 +- go.sum | 2 ++ 26 files changed, 76 insertions(+), 58 deletions(-) diff --git a/.hof/Cli/cmd/mvs/cmd/convert.go b/.hof/Cli/cmd/mvs/cmd/convert.go index dd33df6..65a5dae 100644 --- a/.hof/Cli/cmd/mvs/cmd/convert.go +++ b/.hof/Cli/cmd/mvs/cmd/convert.go @@ -38,7 +38,7 @@ var ConvertCmd = &cobra.Command{ cs := strings.Fields(cmd.CommandPath()) c := strings.Join(cs[1:], "/") - ga.SendGaEvent(c, strings.Join(args, "/"), 0) + ga.SendGaEvent(c, "", 0) }, diff --git a/.hof/Cli/cmd/mvs/cmd/graph.go b/.hof/Cli/cmd/mvs/cmd/graph.go index 676ab01..f34264b 100644 --- a/.hof/Cli/cmd/mvs/cmd/graph.go +++ b/.hof/Cli/cmd/mvs/cmd/graph.go @@ -38,7 +38,7 @@ var GraphCmd = &cobra.Command{ cs := strings.Fields(cmd.CommandPath()) c := strings.Join(cs[1:], "/") - ga.SendGaEvent(c, strings.Join(args, "/"), 0) + ga.SendGaEvent(c, "", 0) }, diff --git a/.hof/Cli/cmd/mvs/cmd/hack.go b/.hof/Cli/cmd/mvs/cmd/hack.go index f05dfe4..aca8345 100644 --- a/.hof/Cli/cmd/mvs/cmd/hack.go +++ b/.hof/Cli/cmd/mvs/cmd/hack.go @@ -40,7 +40,7 @@ var HackCmd = &cobra.Command{ cs := strings.Fields(cmd.CommandPath()) c := strings.Join(cs[1:], "/") - ga.SendGaEvent(c, strings.Join(args, "/"), 0) + ga.SendGaEvent(c, "", 0) }, diff --git a/.hof/Cli/cmd/mvs/cmd/info.go b/.hof/Cli/cmd/mvs/cmd/info.go index 1556369..7043747 100644 --- a/.hof/Cli/cmd/mvs/cmd/info.go +++ b/.hof/Cli/cmd/mvs/cmd/info.go @@ -41,7 +41,7 @@ var InfoCmd = &cobra.Command{ cs := strings.Fields(cmd.CommandPath()) c := strings.Join(cs[1:], "/") - ga.SendGaEvent(c, strings.Join(args, "/"), 0) + ga.SendGaEvent(c, "", 0) }, diff --git a/.hof/Cli/cmd/mvs/cmd/init.go b/.hof/Cli/cmd/mvs/cmd/init.go index 639caf7..d821fe5 100644 --- a/.hof/Cli/cmd/mvs/cmd/init.go +++ b/.hof/Cli/cmd/mvs/cmd/init.go @@ -38,7 +38,7 @@ var InitCmd = &cobra.Command{ cs := strings.Fields(cmd.CommandPath()) c := strings.Join(cs[1:], "/") - ga.SendGaEvent(c, strings.Join(args, "/"), 0) + ga.SendGaEvent(c, "", 0) }, diff --git a/.hof/Cli/cmd/mvs/cmd/root.go b/.hof/Cli/cmd/mvs/cmd/root.go index 9b2e3ce..34f4917 100644 --- a/.hof/Cli/cmd/mvs/cmd/root.go +++ b/.hof/Cli/cmd/mvs/cmd/root.go @@ -4,8 +4,6 @@ import ( "fmt" "os" - "strings" - "github.com/spf13/cobra" "github.com/hofstadter-io/mvs/lib" @@ -58,7 +56,7 @@ var RootCmd = &cobra.Command{ PreRun: func(cmd *cobra.Command, args []string) { - ga.SendGaEvent("root", strings.Join(args, "/"), 0) + ga.SendGaEvent("root", "", 0) }, } @@ -68,8 +66,7 @@ func init() { hf := RootCmd.HelpFunc() f := func(cmd *cobra.Command, args []string) { if RootCmd.Name() == cmd.Name() { - as := strings.Join(args, "/") - ga.SendGaEvent("root/help", as, 0) + ga.SendGaEvent("root/help", "", 0) } hf(cmd, args) } diff --git a/.hof/Cli/cmd/mvs/cmd/status.go b/.hof/Cli/cmd/mvs/cmd/status.go index 19d2eda..de1c028 100644 --- a/.hof/Cli/cmd/mvs/cmd/status.go +++ b/.hof/Cli/cmd/mvs/cmd/status.go @@ -38,7 +38,7 @@ var StatusCmd = &cobra.Command{ cs := strings.Fields(cmd.CommandPath()) c := strings.Join(cs[1:], "/") - ga.SendGaEvent(c, strings.Join(args, "/"), 0) + ga.SendGaEvent(c, "", 0) }, diff --git a/.hof/Cli/cmd/mvs/cmd/tidy.go b/.hof/Cli/cmd/mvs/cmd/tidy.go index 4f4e992..c7fb4d1 100644 --- a/.hof/Cli/cmd/mvs/cmd/tidy.go +++ b/.hof/Cli/cmd/mvs/cmd/tidy.go @@ -38,7 +38,7 @@ var TidyCmd = &cobra.Command{ cs := strings.Fields(cmd.CommandPath()) c := strings.Join(cs[1:], "/") - ga.SendGaEvent(c, strings.Join(args, "/"), 0) + ga.SendGaEvent(c, "", 0) }, diff --git a/.hof/Cli/cmd/mvs/cmd/vendor.go b/.hof/Cli/cmd/mvs/cmd/vendor.go index fa0575d..c360248 100644 --- a/.hof/Cli/cmd/mvs/cmd/vendor.go +++ b/.hof/Cli/cmd/mvs/cmd/vendor.go @@ -38,7 +38,7 @@ var VendorCmd = &cobra.Command{ cs := strings.Fields(cmd.CommandPath()) c := strings.Join(cs[1:], "/") - ga.SendGaEvent(c, strings.Join(args, "/"), 0) + ga.SendGaEvent(c, "", 0) }, diff --git a/.hof/Cli/cmd/mvs/cmd/verify.go b/.hof/Cli/cmd/mvs/cmd/verify.go index 6119d8e..6d03d20 100644 --- a/.hof/Cli/cmd/mvs/cmd/verify.go +++ b/.hof/Cli/cmd/mvs/cmd/verify.go @@ -38,7 +38,7 @@ var VerifyCmd = &cobra.Command{ cs := strings.Fields(cmd.CommandPath()) c := strings.Join(cs[1:], "/") - ga.SendGaEvent(c, strings.Join(args, "/"), 0) + ga.SendGaEvent(c, "", 0) }, diff --git a/.hof/Cli/cmd/mvs/ga/ga.go b/.hof/Cli/cmd/mvs/ga/ga.go index 67e5952..0ebfc26 100644 --- a/.hof/Cli/cmd/mvs/ga/ga.go +++ b/.hof/Cli/cmd/mvs/ga/ga.go @@ -13,20 +13,27 @@ import ( ) func SendGaEvent(action, label string, value int) { - // Do something here to lookup / create - // cid := "13b3ad64-9154-11ea-9eba-47f617ab74f7" + if os.Getenv("MVS_TELEMETRY_DISABLED") != "" { + return + } + cid, err := readGaId() if err != nil { - fmt.Println("Error", err) cid = "unknown" } + ua := fmt.Sprintf( + "%s/%s %s/%s", + "mvs", verinfo.Version, + verinfo.BuildOS, verinfo.BuildArch, + ) + cfg := yagu.GaConfig{ TID: "UA-103579574-5", CID: cid, - UA: "mvs/" + verinfo.Version, + UA: ua, CN: "mvs", - CS: "mvs", + CS: "mvs/" + verinfo.Version, CM: verinfo.Version, } @@ -45,11 +52,15 @@ func SendGaEvent(action, label string, value int) { } func readGaId() (string, error) { - ucd := yagu.UserHomeDir() + // ucd := yagu.UserHomeDir() + ucd, err := os.UserConfigDir() + if err != nil { + return "", err + } dir := filepath.Join(ucd, ".hof") fn := filepath.Join(dir, ".uuid") - _, err := os.Lstat(fn) + _, err = os.Lstat(fn) if err != nil { // file does not exist, probably... return writeGaId() @@ -64,16 +75,17 @@ func readGaId() (string, error) { } func writeGaId() (string, error) { - // fmt.Println("writeGaId") - ucd := yagu.UserHomeDir() - dir := filepath.Join(ucd, ".hof") - err := yagu.Mkdir(dir) + ucd, err := os.UserConfigDir() if err != nil { return "", err } - // fmt.Println("Mkdir:", dir) + dir := filepath.Join(ucd, ".hof") + err = yagu.Mkdir(dir) + if err != nil { + return "", err + } fn := filepath.Join(dir, ".uuid") @@ -82,8 +94,6 @@ func writeGaId() (string, error) { return id.String(), err } - // fmt.Println("writeGaId: ", id.String()) - err = ioutil.WriteFile(fn, []byte(id.String()), 0644) if err != nil { return id.String(), err diff --git a/cmd/mvs/cmd/convert.go b/cmd/mvs/cmd/convert.go index dd33df6..65a5dae 100644 --- a/cmd/mvs/cmd/convert.go +++ b/cmd/mvs/cmd/convert.go @@ -38,7 +38,7 @@ var ConvertCmd = &cobra.Command{ cs := strings.Fields(cmd.CommandPath()) c := strings.Join(cs[1:], "/") - ga.SendGaEvent(c, strings.Join(args, "/"), 0) + ga.SendGaEvent(c, "", 0) }, diff --git a/cmd/mvs/cmd/graph.go b/cmd/mvs/cmd/graph.go index 676ab01..f34264b 100644 --- a/cmd/mvs/cmd/graph.go +++ b/cmd/mvs/cmd/graph.go @@ -38,7 +38,7 @@ var GraphCmd = &cobra.Command{ cs := strings.Fields(cmd.CommandPath()) c := strings.Join(cs[1:], "/") - ga.SendGaEvent(c, strings.Join(args, "/"), 0) + ga.SendGaEvent(c, "", 0) }, diff --git a/cmd/mvs/cmd/hack.go b/cmd/mvs/cmd/hack.go index f05dfe4..aca8345 100644 --- a/cmd/mvs/cmd/hack.go +++ b/cmd/mvs/cmd/hack.go @@ -40,7 +40,7 @@ var HackCmd = &cobra.Command{ cs := strings.Fields(cmd.CommandPath()) c := strings.Join(cs[1:], "/") - ga.SendGaEvent(c, strings.Join(args, "/"), 0) + ga.SendGaEvent(c, "", 0) }, diff --git a/cmd/mvs/cmd/info.go b/cmd/mvs/cmd/info.go index 1556369..7043747 100644 --- a/cmd/mvs/cmd/info.go +++ b/cmd/mvs/cmd/info.go @@ -41,7 +41,7 @@ var InfoCmd = &cobra.Command{ cs := strings.Fields(cmd.CommandPath()) c := strings.Join(cs[1:], "/") - ga.SendGaEvent(c, strings.Join(args, "/"), 0) + ga.SendGaEvent(c, "", 0) }, diff --git a/cmd/mvs/cmd/init.go b/cmd/mvs/cmd/init.go index 639caf7..d821fe5 100644 --- a/cmd/mvs/cmd/init.go +++ b/cmd/mvs/cmd/init.go @@ -38,7 +38,7 @@ var InitCmd = &cobra.Command{ cs := strings.Fields(cmd.CommandPath()) c := strings.Join(cs[1:], "/") - ga.SendGaEvent(c, strings.Join(args, "/"), 0) + ga.SendGaEvent(c, "", 0) }, diff --git a/cmd/mvs/cmd/root.go b/cmd/mvs/cmd/root.go index 9b2e3ce..34f4917 100644 --- a/cmd/mvs/cmd/root.go +++ b/cmd/mvs/cmd/root.go @@ -4,8 +4,6 @@ import ( "fmt" "os" - "strings" - "github.com/spf13/cobra" "github.com/hofstadter-io/mvs/lib" @@ -58,7 +56,7 @@ var RootCmd = &cobra.Command{ PreRun: func(cmd *cobra.Command, args []string) { - ga.SendGaEvent("root", strings.Join(args, "/"), 0) + ga.SendGaEvent("root", "", 0) }, } @@ -68,8 +66,7 @@ func init() { hf := RootCmd.HelpFunc() f := func(cmd *cobra.Command, args []string) { if RootCmd.Name() == cmd.Name() { - as := strings.Join(args, "/") - ga.SendGaEvent("root/help", as, 0) + ga.SendGaEvent("root/help", "", 0) } hf(cmd, args) } diff --git a/cmd/mvs/cmd/status.go b/cmd/mvs/cmd/status.go index 19d2eda..de1c028 100644 --- a/cmd/mvs/cmd/status.go +++ b/cmd/mvs/cmd/status.go @@ -38,7 +38,7 @@ var StatusCmd = &cobra.Command{ cs := strings.Fields(cmd.CommandPath()) c := strings.Join(cs[1:], "/") - ga.SendGaEvent(c, strings.Join(args, "/"), 0) + ga.SendGaEvent(c, "", 0) }, diff --git a/cmd/mvs/cmd/tidy.go b/cmd/mvs/cmd/tidy.go index 4f4e992..c7fb4d1 100644 --- a/cmd/mvs/cmd/tidy.go +++ b/cmd/mvs/cmd/tidy.go @@ -38,7 +38,7 @@ var TidyCmd = &cobra.Command{ cs := strings.Fields(cmd.CommandPath()) c := strings.Join(cs[1:], "/") - ga.SendGaEvent(c, strings.Join(args, "/"), 0) + ga.SendGaEvent(c, "", 0) }, diff --git a/cmd/mvs/cmd/vendor.go b/cmd/mvs/cmd/vendor.go index fa0575d..c360248 100644 --- a/cmd/mvs/cmd/vendor.go +++ b/cmd/mvs/cmd/vendor.go @@ -38,7 +38,7 @@ var VendorCmd = &cobra.Command{ cs := strings.Fields(cmd.CommandPath()) c := strings.Join(cs[1:], "/") - ga.SendGaEvent(c, strings.Join(args, "/"), 0) + ga.SendGaEvent(c, "", 0) }, diff --git a/cmd/mvs/cmd/verify.go b/cmd/mvs/cmd/verify.go index 6119d8e..6d03d20 100644 --- a/cmd/mvs/cmd/verify.go +++ b/cmd/mvs/cmd/verify.go @@ -38,7 +38,7 @@ var VerifyCmd = &cobra.Command{ cs := strings.Fields(cmd.CommandPath()) c := strings.Join(cs[1:], "/") - ga.SendGaEvent(c, strings.Join(args, "/"), 0) + ga.SendGaEvent(c, "", 0) }, diff --git a/cmd/mvs/ga/ga.go b/cmd/mvs/ga/ga.go index 67e5952..0ebfc26 100644 --- a/cmd/mvs/ga/ga.go +++ b/cmd/mvs/ga/ga.go @@ -13,20 +13,27 @@ import ( ) func SendGaEvent(action, label string, value int) { - // Do something here to lookup / create - // cid := "13b3ad64-9154-11ea-9eba-47f617ab74f7" + if os.Getenv("MVS_TELEMETRY_DISABLED") != "" { + return + } + cid, err := readGaId() if err != nil { - fmt.Println("Error", err) cid = "unknown" } + ua := fmt.Sprintf( + "%s/%s %s/%s", + "mvs", verinfo.Version, + verinfo.BuildOS, verinfo.BuildArch, + ) + cfg := yagu.GaConfig{ TID: "UA-103579574-5", CID: cid, - UA: "mvs/" + verinfo.Version, + UA: ua, CN: "mvs", - CS: "mvs", + CS: "mvs/" + verinfo.Version, CM: verinfo.Version, } @@ -45,11 +52,15 @@ func SendGaEvent(action, label string, value int) { } func readGaId() (string, error) { - ucd := yagu.UserHomeDir() + // ucd := yagu.UserHomeDir() + ucd, err := os.UserConfigDir() + if err != nil { + return "", err + } dir := filepath.Join(ucd, ".hof") fn := filepath.Join(dir, ".uuid") - _, err := os.Lstat(fn) + _, err = os.Lstat(fn) if err != nil { // file does not exist, probably... return writeGaId() @@ -64,16 +75,17 @@ func readGaId() (string, error) { } func writeGaId() (string, error) { - // fmt.Println("writeGaId") - ucd := yagu.UserHomeDir() - dir := filepath.Join(ucd, ".hof") - err := yagu.Mkdir(dir) + ucd, err := os.UserConfigDir() if err != nil { return "", err } - // fmt.Println("Mkdir:", dir) + dir := filepath.Join(ucd, ".hof") + err = yagu.Mkdir(dir) + if err != nil { + return "", err + } fn := filepath.Join(dir, ".uuid") @@ -82,8 +94,6 @@ func writeGaId() (string, error) { return id.String(), err } - // fmt.Println("writeGaId: ", id.String()) - err = ioutil.WriteFile(fn, []byte(id.String()), 0644) if err != nil { return id.String(), err diff --git a/cue.mods b/cue.mods index 76043d3..54adb1a 100644 --- a/cue.mods +++ b/cue.mods @@ -3,5 +3,5 @@ module github.com/hofstadter-io/mvs cue master require ( - github.com/hofstadter-io/hofmod-cli v0.5.2 + github.com/hofstadter-io/hofmod-cli v0.5.3 ) diff --git a/cue.sums b/cue.sums index 6caa3d3..c13a7dc 100644 --- a/cue.sums +++ b/cue.sums @@ -28,3 +28,5 @@ github.com/hofstadter-io/hofmod-cli v0.5.1 h1:a8Zworm73OyAUxtVPEzibspP5kImka/3D+ github.com/hofstadter-io/hofmod-cli v0.5.1/cue.mods h1:8TVLRMLOvfcVRZu6NqDr4VFmvuw/9Ca7YpCMo1fTRmU= github.com/hofstadter-io/hofmod-cli v0.5.2 h1:LAtrhhLOnuPaAS/P+5E+9Rgq0XmcpRBwuS4iisKZQ1M= github.com/hofstadter-io/hofmod-cli v0.5.2/cue.mods h1:8TVLRMLOvfcVRZu6NqDr4VFmvuw/9Ca7YpCMo1fTRmU= +github.com/hofstadter-io/hofmod-cli v0.5.3 h1:9QcITvHncO6lWHezRnM1YXkVTula6sfsHEQXQh2LI+E= +github.com/hofstadter-io/hofmod-cli v0.5.3/cue.mods h1:8TVLRMLOvfcVRZu6NqDr4VFmvuw/9Ca7YpCMo1fTRmU= diff --git a/go.mod b/go.mod index 0cf3851..1f2394d 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/go-git/go-git/v5 v5.0.0 github.com/google/go-github/v30 v30.1.0 github.com/google/uuid v1.1.1 - github.com/hofstadter-io/yagu v0.0.1 + github.com/hofstadter-io/yagu v0.0.3 github.com/parnurzeal/gorequest v0.2.16 github.com/spf13/cobra v1.0.0 golang.org/x/mod v0.2.0 diff --git a/go.sum b/go.sum index 9640977..a52f89d 100644 --- a/go.sum +++ b/go.sum @@ -118,6 +118,8 @@ github.com/hofstadter-io/hof-lang v0.0.0-20180925221847-4d1c962b0729/go.mod h1:4 github.com/hofstadter-io/mvs v0.5.0/go.mod h1:Cvq23OVa/x1wA720bNCHPgvNuS5+4g2ZWFsWgXfLMUU= github.com/hofstadter-io/yagu v0.0.1 h1:WNtWyXH2vu8C/Il7R2itvgFHHLy/WLqzbm+A+yPYFSc= github.com/hofstadter-io/yagu v0.0.1/go.mod h1:UWTxRZtLMwWDfYcKPaWS6Bc4VZT+ue5P6yJcpS323rM= +github.com/hofstadter-io/yagu v0.0.3 h1:VheQUfbnC7IJ93BN5d1BFBEr6r3CN7loVcG/EpW690o= +github.com/hofstadter-io/yagu v0.0.3/go.mod h1:UWTxRZtLMwWDfYcKPaWS6Bc4VZT+ue5P6yJcpS323rM= github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=