Skip to content

Commit

Permalink
Add no-deploy and generate-name options to 'fly launch' to make it mo…
Browse files Browse the repository at this point in the history
…re useful in CI environments. Also, prompt for a name like 'fly init' did when these options are not used.
  • Loading branch information
jsierles committed Oct 7, 2021
1 parent e6a9156 commit a44b4e1
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 16 deletions.
19 changes: 10 additions & 9 deletions cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"fmt"

"github.com/superfly/flyctl/cmdctx"

"github.com/AlecAivazis/survey/v2"
)

//TODO: Move all output to status styled begin/done updates
Expand All @@ -19,9 +17,11 @@ func runCreate(cmdCtx *cmdctx.CmdContext) error {

name := ""

// If we aren't generating the name automatically, get the name from the command line or from a prompt
if !cmdCtx.Config.GetBool("generate-name") {
name = cmdCtx.Config.GetString("name")

// App name was specified as a command argument and via the --name option
if name != "" && appName != "" {
return fmt.Errorf(`two app names specified %s and %s. Select and specify only one`, appName, name)
}
Expand All @@ -33,14 +33,15 @@ func runCreate(cmdCtx *cmdctx.CmdContext) error {
fmt.Println()

if name == "" {
prompt := &survey.Input{
Message: "App Name (leave blank to use an auto-generated name)",
}
if err := survey.AskOne(prompt, &name); err != nil {
if isInterrupt(err) {
return nil
}

// Prompt the user for the app name
inputName, err := inputAppName("", true)

if err != nil {
return err
}

name = inputName
} else {
fmt.Printf("Selected App Name: %s\n", name)
}
Expand Down
13 changes: 11 additions & 2 deletions cmd/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,20 @@ func selectVMSize(client *api.Client, vmSizeName string) (*api.VMSize, error) {
return &vmSizes[selectedVMSize], nil
}

func inputAppName(defaultName string) (name string, err error) {
func inputAppName(defaultName string, autoGenerate bool) (name string, err error) {
message := "App Name"

if autoGenerate {
message += " (leave blank to use an auto-generated name)"
}

message += ":"

prompt := &survey.Input{
Message: "App name:",
Message: message,
Default: defaultName,
}

if err := survey.AskOne(prompt, &name); err != nil {
return name, err
}
Expand Down
28 changes: 24 additions & 4 deletions cmd/launch.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ func newLaunchCommand(client *client.Client) *Command {
launchCmd.AddStringFlag(StringFlagOpts{Name: "region", Description: "the region to launch the new app in"})
launchCmd.AddStringFlag(StringFlagOpts{Name: "image", Description: "the image to launch"})
launchCmd.AddBoolFlag(BoolFlagOpts{Name: "now", Description: "deploy now without confirmation", Default: false})
launchCmd.AddBoolFlag(BoolFlagOpts{Name: "no-deploy", Description: "Do not prompt for deployment", Default: false})
launchCmd.AddBoolFlag(BoolFlagOpts{Name: "generate-name", Description: "Always generate a name for the app", Default: false})

return launchCmd
}
Expand Down Expand Up @@ -148,7 +150,25 @@ func runLaunch(cmdctx *cmdctx.CmdContext) error {
}
}

appName := cmdctx.Config.GetString("name")
appName := ""

if !cmdctx.Config.GetBool("generate-name") {
appName = cmdctx.Config.GetString("name")

if appName == "" {
// Prompt the user for the app name
inputName, err := inputAppName("", true)

if err != nil {
return err
}

appName = inputName
} else {
fmt.Printf("Selected App Name: %s\n", appName)
}
}

org, err := selectOrganization(cmdctx.Client.API(), orgSlug, nil)
if err != nil {
return err
Expand Down Expand Up @@ -235,11 +255,11 @@ func runLaunch(cmdctx *cmdctx.CmdContext) error {

fmt.Println("Your app is ready. Deploy with `flyctl deploy`")

if !cmdctx.Config.GetBool("now") && !confirm("Would you like to deploy now?") {
return nil
if !cmdctx.Config.GetBool("no-deploy") && (cmdctx.Config.GetBool("now") || confirm("Would you like to deploy now?")) {
return runDeploy(cmdctx)
}

return runDeploy(cmdctx)
return nil
}

func shouldDeployExistingApp(cc *cmdctx.CmdContext, appName string) (bool, error) {
Expand Down
2 changes: 1 addition & 1 deletion cmd/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func runPostgresList(ctx *cmdctx.CmdContext) error {
func runCreatePostgresCluster(ctx *cmdctx.CmdContext) error {
name := ctx.Config.GetString("name")
if name == "" {
n, err := inputAppName("")
n, err := inputAppName("", false)
if err != nil {
return err
}
Expand Down

0 comments on commit a44b4e1

Please sign in to comment.