github.com/helmwave/helmwave@v0.36.4-0.20240509190856-b35563eba4c6/pkg/action/diff_local.go (about) 1 package action 2 3 import ( 4 "context" 5 "os" 6 7 "github.com/helmwave/helmwave/pkg/plan" 8 log "github.com/sirupsen/logrus" 9 "github.com/urfave/cli/v2" 10 ) 11 12 var _ Action = (*DiffLocal)(nil) 13 14 // DiffLocal is a struct for running 'diff plan' command. 15 type DiffLocal struct { 16 diff *Diff 17 plandir1 string 18 plandir2 string 19 } 20 21 // Run is the main function for 'diff plan' command. 22 func (d *DiffLocal) Run(ctx context.Context) error { 23 if d.plandir1 == d.plandir2 { 24 log.Warn(plan.ErrPlansAreTheSame) 25 } 26 27 // Plan 1 28 plan1, err := plan.NewAndImport(ctx, d.plandir1) 29 if err != nil { 30 return err 31 } 32 if ok := plan1.IsManifestExist(); !ok { 33 return os.ErrNotExist 34 } 35 36 // Plan 2 37 plan2, err := plan.NewAndImport(ctx, d.plandir2) 38 if err != nil { 39 return err 40 } 41 if ok := plan2.IsManifestExist(); !ok { 42 return os.ErrNotExist 43 } 44 45 plan1.DiffPlan(plan2, d.diff.Options) 46 47 return nil 48 } 49 50 // Cmd returns 'diff plan' *cli.Command. 51 func (d *DiffLocal) Cmd() *cli.Command { 52 return &cli.Command{ 53 Name: "local", 54 Aliases: []string{"plan"}, 55 Usage: "plan1 🆚 plan2", 56 Flags: d.flags(), 57 Action: toCtx(d.Run), 58 } 59 } 60 61 // flags return flag set of CLI urfave. 62 func (d *DiffLocal) flags() []cli.Flag { 63 return []cli.Flag{ 64 &cli.StringFlag{ 65 Name: "plandir1", 66 Value: ".helmwave/", 67 Usage: "path to plandir1", 68 EnvVars: []string{"HELMWAVE_PLANDIR_1", "HELMWAVE_PLANDIR"}, 69 Destination: &d.plandir1, 70 }, 71 &cli.StringFlag{ 72 Name: "plandir2", 73 Value: ".helmwave/", 74 Usage: "path to plandir2", 75 EnvVars: []string{"HELMWAVE_PLANDIR_2"}, 76 Destination: &d.plandir2, 77 }, 78 } 79 }