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

Commit 1a6cd11

Browse files
committed
reorganize new and add
re-organize new & add, promote them to top-level, since they are generic for all platforms.
1 parent 65cfb43 commit 1a6cd11

12 files changed

+81
-54
lines changed

parsecmd/add_common.go renamed to add.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
package parsecmd
1+
package main
22

33
import (
44
"github.com/ParsePlatform/parse-cli/parsecli"
5+
"github.com/ParsePlatform/parse-cli/parsecmd"
56
"github.com/facebookgo/stackerr"
67
"github.com/spf13/cobra"
78
)
@@ -24,7 +25,7 @@ func (a *addCmd) addSelectedApp(
2425
if !ok {
2526
return stackerr.New("invalid parse app config passed.")
2627
}
27-
return a.addSelectedParseApp(name, parseAppConfig, args, e)
28+
return parsecmd.AddSelectedParseApp(name, parseAppConfig, args, a.MakeDefault, a.verbose, e)
2829
}
2930

3031
return stackerr.Newf("Unknown project type: %d.", e.Type)
@@ -68,7 +69,7 @@ func (a *addCmd) run(e *parsecli.Env, args []string) error {
6869
if err != nil {
6970
return err
7071
}
71-
appConfig := a.getParseAppConfig(app)
72+
appConfig := parsecmd.GetParseAppConfig(app)
7273
return a.addSelectedApp(app.Name, appConfig, args, e)
7374
}
7475

parsecmd/add_test.go renamed to add_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package parsecmd
1+
package main
22

33
import (
44
"encoding/json"

parsecmd/migrate.go renamed to migrate.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package parsecmd
1+
package main
22

33
import (
44
"fmt"

parsecmd/migrate_test.go renamed to migrate_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package parsecmd
1+
package main
22

33
import (
44
"io/ioutil"

parsecmd/new_common.go renamed to new.go

+5-37
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package parsecmd
1+
package main
22

33
import (
44
"fmt"
@@ -7,6 +7,7 @@ import (
77
"strings"
88

99
"github.com/ParsePlatform/parse-cli/parsecli"
10+
"github.com/ParsePlatform/parse-cli/parsecmd"
1011
"github.com/facebookgo/parse"
1112
"github.com/facebookgo/stackerr"
1213
"github.com/spf13/cobra"
@@ -209,40 +210,7 @@ Please type [y] if you wish to download the current Cloud Code or [n] for blank
209210
n.configOnly = true
210211
}
211212
}
212-
213-
dumpTemplate := false
214-
if !isNew && !n.configOnly {
215-
// if parse app was already created try to fetch cloud code and populate dir
216-
masterKey, err := appConfig.GetMasterKey(e)
217-
if err != nil {
218-
return false, err
219-
}
220-
e.ParseAPIClient = e.ParseAPIClient.WithCredentials(
221-
parse.MasterKey{
222-
ApplicationID: appConfig.GetApplicationID(),
223-
MasterKey: masterKey,
224-
},
225-
)
226-
227-
d := &downloadCmd{destination: e.Root}
228-
err = d.run(e, nil)
229-
if err != nil {
230-
if err == errNoFiles {
231-
dumpTemplate = true
232-
} else {
233-
fmt.Fprintln(
234-
e.Out,
235-
`
236-
NOTE: If you like to fetch the latest deployed Cloud Code from Parse,
237-
you can use the "parse download" command after finishing the set up.
238-
This will download Cloud Code to a temporary location.
239-
`,
240-
)
241-
}
242-
}
243-
}
244-
dumpTemplate = (isNew || dumpTemplate) && !n.configOnly
245-
return dumpTemplate, parsecli.CloneSampleCloudCode(e, dumpTemplate)
213+
return parsecmd.CloneSampleCloudCode(e, isNew, n.configOnly, appConfig)
246214
}
247215
return false, stackerr.Newf("Unknown project type: %d", e.Type)
248216
}
@@ -270,7 +238,7 @@ func (n *newCmd) configureSample(
270238
)
271239

272240
if e.Type == parsecli.ParseFormat {
273-
return useLatestJSSDK(e)
241+
return parsecmd.UseLatestJSSDK(e)
274242
}
275243
return nil
276244
}
@@ -323,7 +291,7 @@ func (n *newCmd) run(e *parsecli.Env) error {
323291
}
324292

325293
e.Type = parsecli.ParseFormat
326-
appConfig := addCmd.getParseAppConfig(app)
294+
appConfig := parsecmd.GetParseAppConfig(app)
327295

328296
dumpTemplate, err := n.setupSample(e, app.Name, appConfig, isNew, nonInteractive)
329297
if err != nil {

parsecmd/new_test.go renamed to new_test.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package parsecmd
1+
package main
22

33
import (
44
"fmt"
@@ -216,6 +216,9 @@ func TestSetupAndConfigure(t *testing.T) {
216216
ensure.Nil(t, err)
217217
ensure.True(t, code)
218218

219+
type jsSDKVersion struct {
220+
JS []string `json:"js"`
221+
}
219222
ht := parsecli.TransportFunc(func(r *http.Request) (*http.Response, error) {
220223
ensure.DeepEqual(t, r.URL.Path, "/1/jsVersions")
221224
rows := jsSDKVersion{JS: []string{"1.5.0", "1.6.0"}}

parse_commands.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ http://parse.com`,
2626
},
2727
}
2828

29-
c.AddCommand(parsecmd.NewAddCmd(e))
29+
c.AddCommand(NewAddCmd(e))
3030
c.AddCommand(NewConfigureCmd(e))
3131
c.AddCommand(NewDefaultCmd(e))
3232
c.AddCommand(parsecmd.NewDeployCmd(e))
@@ -37,8 +37,8 @@ http://parse.com`,
3737
c.AddCommand(parsecmd.NewJsSdkCmd(e))
3838
c.AddCommand(NewListCmd(e))
3939
c.AddCommand(parsecmd.NewLogsCmd(e))
40-
c.AddCommand(parsecmd.NewMigrateCmd(e))
41-
c.AddCommand(parsecmd.NewNewCmd(e))
40+
c.AddCommand(NewMigrateCmd(e))
41+
c.AddCommand(NewNewCmd(e))
4242
c.AddCommand(parsecmd.NewReleasesCmd(e))
4343
c.AddCommand(parsecmd.NewRollbackCmd(e))
4444
c.AddCommand(parsecmd.NewSymbolsCmd(e))

parsecmd/add.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,18 @@ import (
77
"github.com/facebookgo/stackerr"
88
)
99

10-
func (a *addCmd) getParseAppConfig(app *parsecli.App) *parsecli.ParseAppConfig {
10+
func GetParseAppConfig(app *parsecli.App) *parsecli.ParseAppConfig {
1111
pc := &parsecli.ParseAppConfig{
1212
ApplicationID: app.ApplicationID,
1313
}
1414
return pc.WithInternalMasterKey(app.MasterKey)
1515
}
1616

17-
func (a *addCmd) addSelectedParseApp(
17+
func AddSelectedParseApp(
1818
appName string,
1919
appConfig *parsecli.ParseAppConfig,
2020
args []string,
21+
makeDefault, verbose bool,
2122
e *parsecli.Env,
2223
) error {
2324
config, err := parsecli.ConfigFromDir(e.Root)
@@ -48,7 +49,7 @@ func (a *addCmd) addSelectedParseApp(
4849
}
4950
}
5051

51-
if a.MakeDefault {
52+
if makeDefault {
5253
if _, ok := parseConfig.Applications[parsecli.DefaultKey]; ok {
5354
return stackerr.New(`Default key already set. To override default, use command "parse default"`)
5455
}
@@ -58,9 +59,9 @@ func (a *addCmd) addSelectedParseApp(
5859
if err := parsecli.StoreConfig(e, parseConfig); err != nil {
5960
return err
6061
}
61-
if a.verbose {
62+
if verbose {
6263
fmt.Fprintf(e.Out, "Written config for %q\n", appName)
63-
if a.MakeDefault {
64+
if makeDefault {
6465
fmt.Fprintf(e.Out, "Set %q as default\n", appName)
6566
}
6667
}

parsecmd/deploy.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ func (d *deployCmd) deploy(
363363
fmt.Fprintln(e.Err,
364364
"JS SDK version not set, setting it to latest available JS SDK version",
365365
)
366-
if err := useLatestJSSDK(e); err != nil {
366+
if err := UseLatestJSSDK(e); err != nil {
367367
return nil, err
368368
}
369369
}

parsecmd/deploy_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package parsecmd
22

33
import (
4+
"encoding/json"
45
"fmt"
56
"io/ioutil"
67
"net/http"
@@ -16,6 +17,12 @@ import (
1617
"github.com/facebookgo/parse"
1718
)
1819

20+
func jsonStr(t testing.TB, v interface{}) string {
21+
b, err := json.Marshal(v)
22+
ensure.Nil(t, err)
23+
return string(b)
24+
}
25+
1926
func createParseProject(t testing.TB) *parsecli.Harness {
2027
h := parsecli.NewHarness(t)
2128
h.MakeEmptyRoot()

parsecmd/jssdk.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func (j *jsSDKCmd) setVersion(e *parsecli.Env, c *parsecli.Context) error {
9090

9191
// useLatestJSSDK is a utility method used by deploy & develop
9292
// to write set jssdk version to latest available, if none set
93-
func useLatestJSSDK(e *parsecli.Env) error {
93+
func UseLatestJSSDK(e *parsecli.Env) error {
9494
var j jsSDKCmd
9595
versions, err := j.getAllJSSdks(e)
9696
if err != nil {

parsecmd/new.go

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package parsecmd
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/ParsePlatform/parse-cli/parsecli"
7+
"github.com/facebookgo/parse"
8+
)
9+
10+
func CloneSampleCloudCode(
11+
e *parsecli.Env,
12+
isNew, configOnly bool,
13+
appConfig parsecli.AppConfig) (bool, error) {
14+
dumpTemplate := false
15+
if !isNew && !configOnly {
16+
// if parse app was already created try to fetch cloud code and populate dir
17+
masterKey, err := appConfig.GetMasterKey(e)
18+
if err != nil {
19+
return false, err
20+
}
21+
e.ParseAPIClient = e.ParseAPIClient.WithCredentials(
22+
parse.MasterKey{
23+
ApplicationID: appConfig.GetApplicationID(),
24+
MasterKey: masterKey,
25+
},
26+
)
27+
28+
d := &downloadCmd{destination: e.Root}
29+
err = d.run(e, nil)
30+
if err != nil {
31+
if err == errNoFiles {
32+
dumpTemplate = true
33+
} else {
34+
fmt.Fprintln(
35+
e.Out,
36+
`
37+
NOTE: If you like to fetch the latest deployed Cloud Code from Parse,
38+
you can use the "parse download" command after finishing the set up.
39+
This will download Cloud Code to a temporary location.
40+
`,
41+
)
42+
}
43+
}
44+
}
45+
dumpTemplate = (isNew || dumpTemplate) && !configOnly
46+
return dumpTemplate, parsecli.CloneSampleCloudCode(e, dumpTemplate)
47+
}

0 commit comments

Comments
 (0)