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

Commit

Permalink
record mode of operation of command line
Browse files Browse the repository at this point in the history
- command line can run in 2 modes, parse/heroku
- record which mode it was run in for debugging
  • Loading branch information
pavanka committed Oct 30, 2015
1 parent 759ab05 commit eb09eb1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
14 changes: 14 additions & 0 deletions herokucmd/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io"
"io/ioutil"
"net/http"
"net/url"
"os"
"path/filepath"

Expand All @@ -17,6 +18,17 @@ const (
nodeSampleBase = "node-sample"
)

func recordDecision(e *parsecli.Env, decision string) {
v := make(url.Values)
v.Set("version", parsecli.Version)
v.Set("decision", decision)
req := &http.Request{
Method: "GET",
URL: &url.URL{Path: "supported", RawQuery: v.Encode()},
}
e.ParseAPIClient.Do(req, nil, nil)
}

func PromptCreateWebhooks(e *parsecli.Env) (string, error) {
selections := map[int]string{
1: "Heroku (https://www.heroku.com)",
Expand All @@ -40,8 +52,10 @@ Type 1 or 2 to make a selection: `,
fmt.Fprintln(e.Out)
switch projectType {
case 1:
recordDecision(e, "heroku")
return "heroku", nil
case 2:
recordDecision(e, "parse")
return "parse", nil
}
fmt.Fprintln(e.Err, msg)
Expand Down
8 changes: 6 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,18 @@ func main() {
rootCmd *cobra.Command
command []string
)
var mode string
switch e.Type {
case parsecli.LegacyParseFormat, parsecli.ParseFormat:
mode = "parse"
command, rootCmd = parseRootCmd(&e)
case parsecli.HerokuFormat:
mode = "heroku"
command, rootCmd = herokuRootCmd(&e)
}

if len(command) == 0 || command[0] != "update" {
message, err := checkIfSupported(&e, parsecli.Version, command...)
message, err := checkIfSupported(&e, parsecli.Version, mode, command...)
if err != nil {
fmt.Fprintln(e.Err, err)
os.Exit(1)
Expand All @@ -111,9 +114,10 @@ func main() {
}
}

func checkIfSupported(e *parsecli.Env, version string, args ...string) (string, error) {
func checkIfSupported(e *parsecli.Env, version string, mode string, args ...string) (string, error) {
v := make(url.Values)
v.Set("version", version)
v.Set("mode", mode)
v.Set("other", strings.Join(args, " "))
req := &http.Request{
Method: "GET",
Expand Down
4 changes: 2 additions & 2 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestIsSupportedWarning(t *testing.T) {
}, nil
})
h.Env.ParseAPIClient = &parsecli.ParseAPIClient{APIClient: &parse.Client{Transport: ht}}
message, err := checkIfSupported(h.Env, "2.0.2")
message, err := checkIfSupported(h.Env, "2.0.2", "parse")
ensure.Nil(t, err)
ensure.DeepEqual(t, message, "please update")
}
Expand All @@ -60,7 +60,7 @@ func TestIsSupportedError(t *testing.T) {
}, nil
})
h.Env.ParseAPIClient = &parsecli.ParseAPIClient{APIClient: &parse.Client{Transport: ht}}
_, err := checkIfSupported(h.Env, "2.0.2")
_, err := checkIfSupported(h.Env, "2.0.2", "parse")
ensure.Err(t, err, regexp.MustCompile("not supported"))
}

Expand Down

0 comments on commit eb09eb1

Please sign in to comment.