Skip to content
This repository was archived by the owner on Jan 16, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions download_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"crypto/md5"
"errors"
"fmt"
"io"
"io/ioutil"
Expand All @@ -22,6 +23,8 @@ type downloadCmd struct {
force bool
}

var errNoFiles = errors.New("Nothing to download. Not yet deployed to the app.")

func (d *downloadCmd) verifyChecksum(path, checksum string) error {
file, err := os.Open(path)
if err != nil {
Expand Down Expand Up @@ -243,6 +246,9 @@ func (d *downloadCmd) run(e *env, c *context) error {
if err != nil {
return err
}
if len(latestRelease.Versions.Cloud) == 0 && len(latestRelease.Versions.Public) == 0 {
return errNoFiles
}
}

destination := d.destination
Expand Down
32 changes: 21 additions & 11 deletions new.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,15 @@ Type "(n)ew" or "(e)xisting": `,
return "", stackerr.New(msg)
}

func (n *newCmd) setupSample(e *env, app *app, isNew bool, nonInteractive bool) error {
func (n *newCmd) setupSample(e *env, app *app, isNew bool, nonInteractive bool) (bool, error) {
found := isProjectDir(getProjectRoot(e, e.Root))
if !found {
root := getLegacyProjectRoot(e, e.Root)
_, err := os.Lstat(filepath.Join(root, legacyConfigFile))
found = err == nil
}
if found {
return stackerr.New(
return false, stackerr.New(
`Detected that you are already inside a Parse project.
Please refrain from creating a Parse project inside another Parse project.
`,
Expand All @@ -202,13 +202,14 @@ Please refrain from creating a Parse project inside another Parse project.
} else {
cloudCodeDir, err = n.getCloudCodeDir(e, app.Name, isNew)
if err != nil {
return err
return false, err
}
}
e.Root = filepath.Join(e.Root, cloudCodeDir)

switch e.Type {
case parseFormat:
dumpTemplate := false
if !isNew && !n.noCode {
// if parse app was already created try to fetch cloud code and populate dir
e.ParseAPIClient = e.ParseAPIClient.WithCredentials(
Expand All @@ -221,19 +222,24 @@ Please refrain from creating a Parse project inside another Parse project.
d := &downloadCmd{destination: e.Root}
err = d.run(e, nil)
if err != nil {
fmt.Fprintln(
e.Out,
`
if err == errNoFiles {
dumpTemplate = true
} else {
fmt.Fprintln(
e.Out,
`
NOTE: If you like to fetch the latest deployed Cloud Code from Parse,
you can use the "parse download" command after finishing the set up.
This will download Cloud Code to a temporary location.
`,
)
)
}
}
}
return n.cloneSampleCloudCode(e, app, isNew, isNew && !n.noCode)
dumpTemplate = (isNew || dumpTemplate) && !n.noCode
return dumpTemplate, n.cloneSampleCloudCode(e, app, isNew, dumpTemplate)
}
return stackerr.Newf("Unknown project type: %d", e.Type)
return false, stackerr.Newf("Unknown project type: %d", e.Type)
}

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

e.Type = parseFormat

if err := n.setupSample(e, app, isNew, nonInteractive); err != nil {
dumpTemplate, err := n.setupSample(e, app, isNew, nonInteractive)
if err != nil {
return err
}
if err := n.configureSample(addCmd, app, nil, e); err != nil {
Expand All @@ -310,7 +317,10 @@ func (n *newCmd) run(e *env) error {
}
}

fmt.Fprintf(e.Out, n.cloudCodeHelpMessage(e, app))
if dumpTemplate {
fmt.Fprintf(e.Out, n.cloudCodeHelpMessage(e, app))
}

return nil
}

Expand Down