Skip to content
This repository was archived by the owner on Jan 16, 2021. It is now read-only.

Commit eb09eb1

Browse files
committed
record mode of operation of command line
- command line can run in 2 modes, parse/heroku - record which mode it was run in for debugging
1 parent 759ab05 commit eb09eb1

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

herokucmd/new.go

+14
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"io"
66
"io/ioutil"
77
"net/http"
8+
"net/url"
89
"os"
910
"path/filepath"
1011

@@ -17,6 +18,17 @@ const (
1718
nodeSampleBase = "node-sample"
1819
)
1920

21+
func recordDecision(e *parsecli.Env, decision string) {
22+
v := make(url.Values)
23+
v.Set("version", parsecli.Version)
24+
v.Set("decision", decision)
25+
req := &http.Request{
26+
Method: "GET",
27+
URL: &url.URL{Path: "supported", RawQuery: v.Encode()},
28+
}
29+
e.ParseAPIClient.Do(req, nil, nil)
30+
}
31+
2032
func PromptCreateWebhooks(e *parsecli.Env) (string, error) {
2133
selections := map[int]string{
2234
1: "Heroku (https://www.heroku.com)",
@@ -40,8 +52,10 @@ Type 1 or 2 to make a selection: `,
4052
fmt.Fprintln(e.Out)
4153
switch projectType {
4254
case 1:
55+
recordDecision(e, "heroku")
4356
return "heroku", nil
4457
case 2:
58+
recordDecision(e, "parse")
4559
return "parse", nil
4660
}
4761
fmt.Fprintln(e.Err, msg)

main.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,18 @@ func main() {
8787
rootCmd *cobra.Command
8888
command []string
8989
)
90+
var mode string
9091
switch e.Type {
9192
case parsecli.LegacyParseFormat, parsecli.ParseFormat:
93+
mode = "parse"
9294
command, rootCmd = parseRootCmd(&e)
9395
case parsecli.HerokuFormat:
96+
mode = "heroku"
9497
command, rootCmd = herokuRootCmd(&e)
9598
}
9699

97100
if len(command) == 0 || command[0] != "update" {
98-
message, err := checkIfSupported(&e, parsecli.Version, command...)
101+
message, err := checkIfSupported(&e, parsecli.Version, mode, command...)
99102
if err != nil {
100103
fmt.Fprintln(e.Err, err)
101104
os.Exit(1)
@@ -111,9 +114,10 @@ func main() {
111114
}
112115
}
113116

114-
func checkIfSupported(e *parsecli.Env, version string, args ...string) (string, error) {
117+
func checkIfSupported(e *parsecli.Env, version string, mode string, args ...string) (string, error) {
115118
v := make(url.Values)
116119
v.Set("version", version)
120+
v.Set("mode", mode)
117121
v.Set("other", strings.Join(args, " "))
118122
req := &http.Request{
119123
Method: "GET",

main_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func TestIsSupportedWarning(t *testing.T) {
3737
}, nil
3838
})
3939
h.Env.ParseAPIClient = &parsecli.ParseAPIClient{APIClient: &parse.Client{Transport: ht}}
40-
message, err := checkIfSupported(h.Env, "2.0.2")
40+
message, err := checkIfSupported(h.Env, "2.0.2", "parse")
4141
ensure.Nil(t, err)
4242
ensure.DeepEqual(t, message, "please update")
4343
}
@@ -60,7 +60,7 @@ func TestIsSupportedError(t *testing.T) {
6060
}, nil
6161
})
6262
h.Env.ParseAPIClient = &parsecli.ParseAPIClient{APIClient: &parse.Client{Transport: ht}}
63-
_, err := checkIfSupported(h.Env, "2.0.2")
63+
_, err := checkIfSupported(h.Env, "2.0.2", "parse")
6464
ensure.Err(t, err, regexp.MustCompile("not supported"))
6565
}
6666

0 commit comments

Comments
 (0)