Skip to content

Commit

Permalink
pull in some hofmod-cli updates and bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
verdverm committed May 9, 2020
1 parent 7b77b4f commit 755dad2
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 4 deletions.
64 changes: 62 additions & 2 deletions cmd/hof/ga/ga.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
package ga

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"

"github.com/google/uuid"
"github.com/hofstadter-io/yagu"

"github.com/hofstadter-io/hof/cmd/hof/verinfo"
)

func SendGaEvent(action, label string, value int) {
// Do something here to lookup / create
cid := "13b3ad64-9154-11ea-9eba-47f617ab74f7"
// cid := "13b3ad64-9154-11ea-9eba-47f617ab74f7"
cid, err := readGaId()
if err != nil {
fmt.Println("Error", err)
cid = "unknown"
}

cfg := yagu.GaConfig{
TID: "UA-103579574-5",
CID: cid,
UA: "hof/" + verinfo.Version,
CN: "hof",
CS: "hof",
CN: verinfo.Version,
CM: verinfo.Version,
}

evt := yagu.GaEvent{
Expand All @@ -31,3 +43,51 @@ func SendGaEvent(action, label string, value int) {

yagu.SendGaEvent(cfg, evt)
}

func readGaId() (string, error) {
ucd := yagu.UserHomeDir()
dir := filepath.Join(ucd, ".hof")
fn := filepath.Join(dir, ".uuid")

_, err := os.Lstat(fn)
if err != nil {
// file does not exist, probably...
return writeGaId()
}

content, err := ioutil.ReadFile(fn)
if err != nil {
return writeGaId()
}

return string(content), nil
}

func writeGaId() (string, error) {
// fmt.Println("writeGaId")
ucd := yagu.UserHomeDir()

dir := filepath.Join(ucd, ".hof")
err := yagu.Mkdir(dir)
if err != nil {
return "", err
}

// fmt.Println("Mkdir:", dir)

fn := filepath.Join(dir, ".uuid")

id, err := uuid.NewUUID()
if err != nil {
return id.String(), err
}

// fmt.Println("writeGaId: ", id.String())

err = ioutil.WriteFile(fn, []byte(id.String()), 0644)
if err != nil {
return id.String(), err
}

return id.String(), nil
}
2 changes: 1 addition & 1 deletion cue.mods
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ module github.com/hofstadter-io/hof
cue master

require (
github.com/hofstadter-io/hofmod-cli v0.5.0
github.com/hofstadter-io/hofmod-cli v0.5.2
github.com/hofstadter-io/mvs v0.7.0
)
2 changes: 2 additions & 0 deletions cue.sums
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ github.com/hofstadter-io/hofmod-cli v0.4.0 h1:M9qmHyUW9AxmOAgeAwbfa24L3+GBAuiBhb
github.com/hofstadter-io/hofmod-cli v0.4.0/cue.mods h1:8TVLRMLOvfcVRZu6NqDr4VFmvuw/9Ca7YpCMo1fTRmU=
github.com/hofstadter-io/hofmod-cli v0.5.0 h1:hZT2BUWJftP9jq32bcOElXg1N9oXEFJCK9MxBmfS+24=
github.com/hofstadter-io/hofmod-cli v0.5.0/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/mvs v0.0.0 h1:/rMWV7c92qpH/hyl8Ibi/DSUhrGDgDeKBtFkZeD+SMo=
github.com/hofstadter-io/mvs v0.0.0/cue.mods h1:Bt+zMXYlsncBuI+lyMWfRLObqOt+HNOCAO/DDh1Mf+M=
github.com/hofstadter-io/mvs v0.4.4 h1:hw65QjfvxPjeUimqurEbTuwnDLSj/GUABKsHUymaW2g=
Expand Down
1 change: 1 addition & 0 deletions design/cli-root.cue
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
Releases: #CliReleases

Telemetry: "UA-103579574-5"
TelemetryIdDir: ".hof"

OmitRun: true

Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ require (
github.com/ghodss/yaml v1.0.0
github.com/golang/protobuf v1.4.0 // indirect
github.com/golang/snappy v0.0.1 // indirect
github.com/google/uuid v1.1.1
github.com/hofstadter-io/data-utils v0.0.0-20200128210141-0a3e569b27ed
github.com/hofstadter-io/dotpath v0.0.0-20191027071558-52e2819b7d2d
github.com/hofstadter-io/mvs v0.7.0
github.com/hofstadter-io/structural v0.1.0 // indirect
github.com/hofstadter-io/structural v0.1.2 // indirect
github.com/hofstadter-io/yagu v0.0.1
github.com/kr/pretty v0.1.0
github.com/mattn/go-zglob v0.0.1
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ github.com/google/go-github/v30 v30.1.0 h1:VLDx+UolQICEOKu2m4uAoMti1SxuEBAl7RSEG
github.com/google/go-github/v30 v30.1.0/go.mod h1:n8jBpHl45a/rlBUtRJMOG4GhNADUQFEufcolZ95JfU8=
github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
Expand All @@ -118,6 +120,7 @@ github.com/hofstadter-io/mvs v0.6.0/go.mod h1:Cvq23OVa/x1wA720bNCHPgvNuS5+4g2ZWF
github.com/hofstadter-io/mvs v0.7.0 h1:nBPwfK1wY7NFMlGooYkiXNE6rqbtr4maGtmDU/rmRno=
github.com/hofstadter-io/mvs v0.7.0/go.mod h1:EJm3JgN0ogwttI5KsKVx1V+Nf3lBctDSCJAirph37YQ=
github.com/hofstadter-io/structural v0.1.0/go.mod h1:9TuYfLVHsi8pkqfz7K2SYiE8OAmog7KyX/IHy4BzjRM=
github.com/hofstadter-io/structural v0.1.2/go.mod h1:aBIZ/puy20x0pol1GrIkWg1cy+4+h9pLCBn4NY32z5A=
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/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
Expand Down

0 comments on commit 755dad2

Please sign in to comment.