in internal/pkg/cli/app_init.go [137:212]
func (o *initAppOpts) Ask() error {
ok, err := o.isSessionFromEnvVars()
if err != nil {
return err
}
if ok {
log.Warningln(`Looks like you're creating an application using credentials set by environment variables.
Copilot will store your application metadata in this account.
We recommend using credentials from named profiles. To learn more:
https://aws.github.io/copilot-cli/docs/credentials/`)
log.Infoln()
}
ws, err := o.existingWorkspace()
if err == nil {
// When there's a local application.
summary, err := ws.Summary()
if err == nil {
if o.name == "" {
log.Infoln(fmt.Sprintf(
"Your workspace is registered to application %s.",
color.HighlightUserInput(summary.Application)))
if err := o.validateAppName(summary.Application); err != nil {
return err
}
o.name = summary.Application
return nil
}
if o.name != summary.Application {
summaryPath := displayPath(summary.Path)
if summaryPath == "" {
summaryPath = summary.Path
}
log.Errorf(`Workspace is already registered with application %s instead of %s.
If you'd like to delete the application locally, you can delete the file at %s.
If you'd like to delete the application and all of its resources, run %s.
`,
summary.Application,
o.name,
summaryPath,
color.HighlightCode("copilot app delete"))
return fmt.Errorf("workspace already registered with %s", summary.Application)
}
}
var errNoAppSummary *workspace.ErrNoAssociatedApplication
if !errors.As(err, &errNoAppSummary) {
return err
}
}
if !workspace.IsEmptyErr(err) {
return err
}
// Flag is set by user.
if o.name != "" {
return nil
}
existingApps, _ := o.store.ListApplications()
if len(existingApps) == 0 {
return o.askAppName(fmtAppInitNamePrompt)
}
useExistingApp, err := o.prompt.Confirm(
"Would you like to use one of your existing applications?", "", prompt.WithTrueDefault(), prompt.WithFinalMessage("Use existing application:"))
if err != nil {
return fmt.Errorf("prompt to confirm using existing application: %w", err)
}
if useExistingApp {
return o.askSelectExistingAppName(existingApps)
}
return o.askAppName(fmtAppInitNewNamePrompt)
}