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