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

Commit 0ecfe86

Browse files
committed
[develop] let develop deploy to default app
- let `parse develop` deploy to default app, if no app is provided in arguments. however, ask for confirmation in that case.
1 parent de3d771 commit 0ecfe86

File tree

2 files changed

+31
-10
lines changed

2 files changed

+31
-10
lines changed

parsecli/runners.go

+30-9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package parsecli
22

33
import (
44
"fmt"
5+
"strings"
56

67
"github.com/spf13/cobra"
78
)
@@ -62,29 +63,49 @@ func RunWithClient(e *Env, f func(*Env, *Context) error) cobraRun {
6263
}
6364
}
6465

65-
// RunWithAppClient wraps a run function that should get an app
66-
func RunWithAppClient(e *Env, f func(*Env, *Context) error) cobraRun {
66+
// RunWithClientConfirm wraps a run function that takes an app name
67+
// or asks for confirmation to use the default app name instead
68+
func RunWithClientConfirm(e *Env, f func(*Env, *Context) error) cobraRun {
6769
return func(cmd *cobra.Command, args []string) {
68-
if len(args) == 0 {
69-
fmt.Fprintf(e.Err, "please provide an app name\n\n")
70-
cmd.Help()
71-
e.Exit(1)
72-
}
70+
app := DefaultKey
7371
if len(args) > 1 {
7472
fmt.Fprintf(
7573
e.Err,
76-
"unexpected arguments, only an app name is expected:%+v\n\n",
74+
"unexpected arguments, only an optional app name is expected:%+v\n\n",
7775
args,
7876
)
7977
cmd.Help()
8078
e.Exit(1)
8179
}
82-
app := args[0]
80+
if len(args) == 1 {
81+
app = args[0]
82+
}
8383
cl, err := newContext(e, app)
8484
if err != nil {
8585
fmt.Fprintln(e.Err, ErrorString(e, err))
8686
e.Exit(1)
8787
}
88+
89+
if app == DefaultKey {
90+
fmt.Fprintf(
91+
e.Out,
92+
`Did not provide app name as an argument to the command.
93+
Please enter an app name to execute this command on
94+
or press ENTER to use the default app %q: `,
95+
cl.Config.GetDefaultApp(),
96+
)
97+
var appName string
98+
fmt.Fscanf(e.In, "%s\n", &appName)
99+
appName = strings.TrimSpace(appName)
100+
if appName != "" {
101+
cl, err = newContext(e, appName)
102+
if err != nil {
103+
fmt.Fprintln(e.Err, ErrorString(e, err))
104+
e.Exit(1)
105+
}
106+
}
107+
}
108+
88109
if err := f(e, cl); err != nil {
89110
fmt.Fprintln(e.Err, ErrorString(e, err))
90111
e.Exit(1)

parsecmd/develop.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func NewDevelopCmd(e *parsecli.Env) *cobra.Command {
131131
`This will also monitor the parse INFO log for any new log messages and write ` +
132132
`out updates to the terminal. This requires an app to be provided, to ` +
133133
`avoid running develop on production apps accidently.`,
134-
Run: parsecli.RunWithAppClient(e, d.run),
134+
Run: parsecli.RunWithClientConfirm(e, d.run),
135135
}
136136
cmd.Flags().DurationVarP(&d.deployInterval, "interval", "i", d.deployInterval, "Number of seconds between deploys.")
137137
cmd.Flags().BoolVarP(&d.mustFetch, "fetch", "f", d.mustFetch, "Always fetch previous deployment info from server")

0 commit comments

Comments
 (0)