github.com/taubyte/tau-cli@v0.1.13-0.20240326000942-487f0d57edfc/cli/commands/resources/application/delete.go (about)

     1  package application
     2  
     3  import (
     4  	"github.com/taubyte/tau-cli/cli/common"
     5  	"github.com/taubyte/tau-cli/flags"
     6  	applicationI18n "github.com/taubyte/tau-cli/i18n/application"
     7  	applicationLib "github.com/taubyte/tau-cli/lib/application"
     8  	applicationPrompts "github.com/taubyte/tau-cli/prompts/application"
     9  	applicationTable "github.com/taubyte/tau-cli/table/application"
    10  	"github.com/urfave/cli/v2"
    11  )
    12  
    13  func (link) Delete() common.Command {
    14  	return common.Create(
    15  		&cli.Command{
    16  			Flags: []cli.Flag{
    17  				flags.Select,
    18  				flags.Yes,
    19  			},
    20  			Action: delete,
    21  		},
    22  	)
    23  }
    24  
    25  func delete(ctx *cli.Context) error {
    26  	// If --select is set we should not check the user's currently selected application
    27  	checkEnv := !ctx.Bool(flags.Select.Name)
    28  
    29  	application, err := applicationPrompts.GetOrSelect(ctx, checkEnv)
    30  	if err != nil {
    31  		return err
    32  	}
    33  
    34  	confirm := applicationTable.Confirm(ctx, application, applicationPrompts.DeleteThis)
    35  	if confirm {
    36  		err = applicationLib.Delete(application)
    37  		if err != nil {
    38  			return err
    39  		}
    40  		applicationI18n.Deleted(application.Name)
    41  
    42  		return nil
    43  	}
    44  
    45  	return nil
    46  }