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

Commit a722335

Browse files
author
Pavan Kumar
committed
[new] print curl command only for default template
* print curl command only when default template is output as code
1 parent 5d8778d commit a722335

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

download_cmd.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"crypto/md5"
5+
"errors"
56
"fmt"
67
"io"
78
"io/ioutil"
@@ -22,6 +23,8 @@ type downloadCmd struct {
2223
force bool
2324
}
2425

26+
var errNoFiles = errors.New("Nothing to download. Not yet deployed to the app.")
27+
2528
func (d *downloadCmd) verifyChecksum(path, checksum string) error {
2629
file, err := os.Open(path)
2730
if err != nil {
@@ -243,6 +246,9 @@ func (d *downloadCmd) run(e *env, c *context) error {
243246
if err != nil {
244247
return err
245248
}
249+
if len(latestRelease.Versions.Cloud) == 0 && len(latestRelease.Versions.Public) == 0 {
250+
return errNoFiles
251+
}
246252
}
247253

248254
destination := d.destination

new.go

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,15 @@ Type "(n)ew" or "(e)xisting": `,
177177
return "", stackerr.New(msg)
178178
}
179179

180-
func (n *newCmd) setupSample(e *env, app *app, isNew bool, nonInteractive bool) error {
180+
func (n *newCmd) setupSample(e *env, app *app, isNew bool, nonInteractive bool) (bool, error) {
181181
found := isProjectDir(getProjectRoot(e, e.Root))
182182
if !found {
183183
root := getLegacyProjectRoot(e, e.Root)
184184
_, err := os.Lstat(filepath.Join(root, legacyConfigFile))
185185
found = err == nil
186186
}
187187
if found {
188-
return stackerr.New(
188+
return false, stackerr.New(
189189
`Detected that you are already inside a Parse project.
190190
Please refrain from creating a Parse project inside another Parse project.
191191
`,
@@ -202,13 +202,14 @@ Please refrain from creating a Parse project inside another Parse project.
202202
} else {
203203
cloudCodeDir, err = n.getCloudCodeDir(e, app.Name, isNew)
204204
if err != nil {
205-
return err
205+
return false, err
206206
}
207207
}
208208
e.Root = filepath.Join(e.Root, cloudCodeDir)
209209

210210
switch e.Type {
211211
case parseFormat:
212+
dumpTemplate := false
212213
if !isNew && !n.noCode {
213214
// if parse app was already created try to fetch cloud code and populate dir
214215
e.ParseAPIClient = e.ParseAPIClient.WithCredentials(
@@ -221,19 +222,24 @@ Please refrain from creating a Parse project inside another Parse project.
221222
d := &downloadCmd{destination: e.Root}
222223
err = d.run(e, nil)
223224
if err != nil {
224-
fmt.Fprintln(
225-
e.Out,
226-
`
225+
if err == errNoFiles {
226+
dumpTemplate = true
227+
} else {
228+
fmt.Fprintln(
229+
e.Out,
230+
`
227231
NOTE: If you like to fetch the latest deployed Cloud Code from Parse,
228232
you can use the "parse download" command after finishing the set up.
229233
This will download Cloud Code to a temporary location.
230234
`,
231-
)
235+
)
236+
}
232237
}
233238
}
234-
return n.cloneSampleCloudCode(e, app, isNew, isNew && !n.noCode)
239+
dumpTemplate = (isNew || dumpTemplate) && !n.noCode
240+
return dumpTemplate, n.cloneSampleCloudCode(e, app, isNew, dumpTemplate)
235241
}
236-
return stackerr.Newf("Unknown project type: %d", e.Type)
242+
return false, stackerr.Newf("Unknown project type: %d", e.Type)
237243
}
238244

239245
func (n *newCmd) configureSample(
@@ -294,7 +300,8 @@ func (n *newCmd) run(e *env) error {
294300

295301
e.Type = parseFormat
296302

297-
if err := n.setupSample(e, app, isNew, nonInteractive); err != nil {
303+
dumpTemplate, err := n.setupSample(e, app, isNew, nonInteractive)
304+
if err != nil {
298305
return err
299306
}
300307
if err := n.configureSample(addCmd, app, nil, e); err != nil {
@@ -310,7 +317,10 @@ func (n *newCmd) run(e *env) error {
310317
}
311318
}
312319

313-
fmt.Fprintf(e.Out, n.cloudCodeHelpMessage(e, app))
320+
if dumpTemplate {
321+
fmt.Fprintf(e.Out, n.cloudCodeHelpMessage(e, app))
322+
}
323+
314324
return nil
315325
}
316326

0 commit comments

Comments
 (0)