github.com/helmwave/helmwave@v0.36.4-0.20240509190856-b35563eba4c6/pkg/action/down.go (about)

     1  package action
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/helmwave/helmwave/pkg/plan"
     7  	"github.com/urfave/cli/v2"
     8  )
     9  
    10  var _ Action = (*Down)(nil)
    11  
    12  // Down is a struct for running 'down' command.
    13  type Down struct {
    14  	build     *Build
    15  	autoBuild bool
    16  }
    17  
    18  // Run is the main function for 'down' command.
    19  func (i *Down) Run(ctx context.Context) error {
    20  	if i.autoBuild {
    21  		if err := i.build.Run(ctx); err != nil {
    22  			return err
    23  		}
    24  	}
    25  
    26  	p, err := plan.NewAndImport(ctx, i.build.plandir)
    27  	if err != nil {
    28  		return err
    29  	}
    30  
    31  	return p.Down(ctx)
    32  }
    33  
    34  // Cmd returns 'down' *cli.Command.
    35  func (i *Down) Cmd() *cli.Command {
    36  	return &cli.Command{
    37  		Name:     "down",
    38  		Category: Step2,
    39  		Usage:    "🔪 delete all",
    40  		Flags:    i.flags(),
    41  		Action:   toCtx(i.Run),
    42  	}
    43  }
    44  
    45  // flags return flag set of CLI urfave.
    46  func (i *Down) flags() []cli.Flag {
    47  	// Init sub-structures
    48  	i.build = &Build{}
    49  
    50  	self := []cli.Flag{
    51  		flagAutoBuild(&i.autoBuild),
    52  	}
    53  
    54  	return append(self, i.build.flags()...)
    55  }