github.com/franciscocpg/up@v0.1.10/internal/cli/stack/stack.go (about)

     1  package stack
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/pkg/errors"
     7  	"github.com/tj/go-prompt"
     8  	"github.com/tj/kingpin"
     9  
    10  	"github.com/apex/log"
    11  	"github.com/apex/up/internal/cli/root"
    12  	"github.com/apex/up/internal/stats"
    13  	"github.com/apex/up/internal/util"
    14  )
    15  
    16  func init() {
    17  	cmd := root.Command("stack", "Stack resource management.")
    18  	cmd.Example(`up stack`, "Show status of the stack resources.")
    19  	cmd.Example(`up stack delete`, "Delete the stack resources.")
    20  	delete(cmd)
    21  	show(cmd)
    22  }
    23  
    24  func delete(cmd *kingpin.CmdClause) {
    25  	c := cmd.Command("delete", "Delete configured resources.")
    26  	c.Example(`up stack delete`, "Delete stack with confirmation prompt.")
    27  	c.Example(`up stack delete --force`, "Delete stack without confirmation prompt.")
    28  	c.Example(`up stack delete --async`, "Don't wait for deletion to complete.")
    29  	c.Example(`up stack delete -fa`, "Force asynchronous deletion.")
    30  
    31  	force := c.Flag("force", "Skip the confirmation prompt.").Short('f').Bool()
    32  	async := c.Flag("async", "Perform deletion asynchronously.").Short('a').Bool()
    33  
    34  	c.Action(func(_ *kingpin.ParseContext) error {
    35  		c, p, err := root.Init()
    36  		if err != nil {
    37  			return errors.Wrap(err, "initializing")
    38  		}
    39  
    40  		wait := !*async
    41  		defer util.Pad()()
    42  
    43  		stats.Track("Delete Stack", map[string]interface{}{
    44  			"force": *force,
    45  			"wait":  wait,
    46  		})
    47  
    48  		if !*force && !prompt.Confirm("  Really destroy the stack %q?  ", c.Name) {
    49  			fmt.Printf("\n")
    50  			log.Info("aborting")
    51  			return nil
    52  		}
    53  
    54  		// TODO: multi-region
    55  		return p.DeleteStack(c.Regions[0], wait)
    56  	})
    57  }
    58  
    59  // TODO: rename status, info, show? decide on conventions
    60  func show(cmd *kingpin.CmdClause) {
    61  	c := cmd.Command("show", "Show status of resources.").Default()
    62  
    63  	c.Action(func(_ *kingpin.ParseContext) error {
    64  		c, p, err := root.Init()
    65  		if err != nil {
    66  			return errors.Wrap(err, "initializing")
    67  		}
    68  
    69  		stats.Track("Show Stack", nil)
    70  
    71  		// TODO: multi-region
    72  		return p.ShowStack(c.Regions[0])
    73  	})
    74  }