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

File tree

12 files changed

+81
-54
lines changed

12 files changed

+81
-54
lines changed
Lines changed: 4 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package parsecmd
1+
package main
22

33
import (
44
"encoding/json"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package parsecmd
1+
package main
22

33
import (
44
"fmt"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package parsecmd
1+
package main
22

33
import (
44
"io/ioutil"
Lines changed: 5 additions & 37 deletions
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 {
Lines changed: 4 additions & 1 deletion
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 6 additions & 5 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 7 additions & 0 deletions
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()

0 commit comments

Comments
 (0)