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

     1  package action
     2  
     3  import (
     4  	"context"
     5  	"os"
     6  
     7  	"github.com/helmwave/helmwave/pkg/plan"
     8  	"github.com/urfave/cli/v2"
     9  )
    10  
    11  var _ Action = (*DiffLive)(nil)
    12  
    13  // DiffLive is a struct for running 'diff live' command.
    14  type DiffLive struct {
    15  	diff    *Diff
    16  	plandir string
    17  }
    18  
    19  // Run is the main function for 'diff live' command.
    20  func (d *DiffLive) Run(ctx context.Context) error {
    21  	p, err := plan.NewAndImport(ctx, d.plandir)
    22  	if err != nil {
    23  		return err
    24  	}
    25  
    26  	if ok := p.IsManifestExist(); !ok {
    27  		return os.ErrNotExist
    28  	}
    29  
    30  	p.DiffLive(ctx, d.diff.Options, d.diff.ThreeWayMerge)
    31  
    32  	return nil
    33  }
    34  
    35  // Cmd returns 'diff live' *cli.Command.
    36  func (d *DiffLive) Cmd() *cli.Command {
    37  	return &cli.Command{
    38  		Name:   "live",
    39  		Usage:  "plan 🆚 live",
    40  		Flags:  d.flags(),
    41  		Action: toCtx(d.Run),
    42  	}
    43  }
    44  
    45  // flags return flag set of CLI urfave.
    46  func (d *DiffLive) flags() []cli.Flag {
    47  	return []cli.Flag{
    48  		flagPlandir(&d.plandir),
    49  		flagDiffThreeWayMerge(&d.diff.ThreeWayMerge),
    50  	}
    51  }