New 🌊 wave for @helm

Commit 6ec7ebce

6ec7ebce14e4Merged

zhilyaev <[email protected]> · 5 years ago · 17 files · ~15 modified · -2 deleted

Description

WIP: struct of plan.Build()

Details

Commit
6ec7ebce14e4
Parent
5835935d1951

pkg/action/build.gomodifiedView file

@@ -2,22 +2,41 @@
22
33 import (
44 "github.com/helmwave/helmwave/pkg/plan"
5+ log "github.com/sirupsen/logrus"
56 "github.com/urfave/cli/v2"
7+ "sort"
8+ "strings"
69 )
710
811 type Build struct {
9- plandir string
10- tags []string
12+ plandir string
13+ tags cli.StringSlice
14+ matchAll bool
1115 }
1216
1317 func (i *Build) Run() error {
14- p := plan.New(i.plandir)
15- return p.Build()
18+ //tags := normalizeTags(i.tags)
19+ newPlan := plan.New(i.plandir)
20+ newPlan.Build()
21+
22+ oldPlan := plan.New(i.plandir)
23+ if oldPlan.IsExist() {
24+ if err := oldPlan.Import(); err != nil {
25+ return err
26+ }
27+
28+ // Show difference
29+ changelog, err := newPlan.Diff(oldPlan)
30+ log.Info(changelog)
31+ if err != nil {
32+ return err
33+ }
34+ }
35+
36+ return newPlan.Export()
1637 }
1738
1839 func (i *Build) Cmd() *cli.Command {
19- t := cli.StringSlice{}
20- i.tags = t.Value()
2140 return &cli.Command{
2241 Name: "build",
2342 Usage: "Build a plandir",
@@ -34,9 +53,28 @@
3453 Aliases: []string{"t"},
3554 Usage: "It allows you choose releases for sync. Example: -t tag1 -t tag3,tag4",
3655 EnvVars: []string{"HELMWAVE_TAGS"},
37- Destination: &t,
56+ Destination: &i.tags,
57+ },
58+ &cli.BoolFlag{
59+ Name: "match-all-tags",
60+ Usage: "Match all provided tags",
61+ Value: false,
62+ EnvVars: []string{"HELMWAVE_MATCH_ALL_TAGS"},
63+ Destination: &i.matchAll,
3864 },
3965 },
4066 Action: toCtx(i.Run),
4167 }
4268 }
69+
70+// normalizeTags normalizes and splits comma-separated tag list.
71+// ["c", " b ", "a "] -> ["a", "b", "c"].
72+func normalizeTags(tags []string) []string {
73+ m := make([]string, len(tags))
74+ for i, t := range tags {
75+ m[i] = strings.TrimSpace(t)
76+ }
77+ sort.Strings(m)
78+
79+ return m
80+}