@@ -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.
190190Please 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+ `
227231NOTE: If you like to fetch the latest deployed Cloud Code from Parse,
228232you can use the "parse download" command after finishing the set up.
229233This 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
239245func (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