Skip to content

Commit

Permalink
launch: nudge users to fly deploy if they can see app with the cu…
Browse files Browse the repository at this point in the history
…rrent app name (#3622)

* `launch`: prompt users to deploy instead if they can see the named app

* `launch`: remove requirement on copied config for deploy prompt
  • Loading branch information
alichay committed Jun 14, 2024
1 parent ba27404 commit 549ddcb
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions internal/command/launch/plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"os"
"path/filepath"
"reflect"
"regexp"
Expand Down Expand Up @@ -161,6 +162,12 @@ func buildManifest(ctx context.Context, recoverableErrors *recoverableErrorBuild
}
}

// If the user can see an app with the same name as what they're about to launch,
// they *probably* want to deploy to that app instead.
if err := nudgeTowardsDeploy(ctx, appName); err != nil {
return nil, nil, err
}

compute, computeExplanation, err := determineCompute(ctx, appConfig, srcInfo)
if err != nil {
if err := recoverableErrors.tryRecover(err); err != nil {
Expand Down Expand Up @@ -249,6 +256,40 @@ func buildManifest(ctx context.Context, recoverableErrors *recoverableErrorBuild
}, buildCache, nil
}

// Check to see if they own the named app, and if so, prompt them to try deploying instead.
func nudgeTowardsDeploy(ctx context.Context, appName string) error {

client := flyutil.ClientFromContext(ctx)
io := iostreams.FromContext(ctx)

if flag.GetYes(ctx) {
return nil
}

if _, err := client.GetApp(ctx, appName); err != nil {
// The user can't see the app. Let them proceed.
return nil
}

// The user can see the app. Prompt them to deploy.
fmt.Fprintf(io.Out, "App '%s' already exists. You can deploy to it with `fly deploy`.\n", appName)

switch confirmed, err := prompt.Confirm(ctx, "Continue launching a new app? "); {
case err == nil:
if !confirmed {
// We've redirected the user to use 'fly deploy'
// Exit directly with code 0 so this isn't flagged as a failed launch
os.Exit(0)
}
case prompt.IsNonInteractive(err):
// Should be impossible - we're only called if recoverableErrors.canEnterUi is true
return nil
default:
return err
}
return nil
}

func stateFromManifest(ctx context.Context, m LaunchManifest, optionalCache *planBuildCache, recoverableErrors *recoverableErrorBuilder) (*launchState, error) {
var (
io = iostreams.FromContext(ctx)
Expand Down

0 comments on commit 549ddcb

Please sign in to comment.