-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.go
More file actions
107 lines (90 loc) · 2.15 KB
/
Copy pathmain.go
File metadata and controls
107 lines (90 loc) · 2.15 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package main
import (
"fmt"
"log"
"os"
"slices"
"context"
"github.com/go-git/go-git/v5"
"github.com/urfave/cli/v3"
"github.com/vexxhost/chart-vendor/internal/chart_vendor"
"github.com/vexxhost/chart-vendor/internal/config"
"golang.org/x/sync/errgroup"
)
func main() {
app := &cli.Command{
Name: "Chart Vendor CLI",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "config-file",
Usage: "Configuration file for the vendored charts",
Value: ".charts.yml",
},
&cli.StringFlag{
Name: "charts-root",
Usage: "Root path where charts are generated",
Value: "charts",
},
&cli.BoolFlag{
Name: "check",
Usage: "Check if all chart manifests are applied or not",
Value: false,
},
},
Action: func(ctx context.Context, cmd *cli.Command) error {
configFile := cmd.String("config-file")
parsedConfig, err := config.ParseFromFile(configFile)
if err != nil {
return err
}
g := errgroup.Group{}
selectedCharts := cmd.Args().Slice()
for _, chart := range parsedConfig.Charts {
if len(selectedCharts) != 0 && !slices.Contains(selectedCharts, chart.Name) {
continue
}
g.Go(func() error {
return chart_vendor.FetchChart(chart, cmd.String("charts-root"))
})
}
err = g.Wait()
if err != nil {
return err
}
if cmd.Bool("check") {
repo, err := git.PlainOpen(".")
if err != nil {
return err
}
worktree, err := repo.Worktree()
if err != nil {
return err
}
status, err := worktree.Status()
if err != nil {
return err
}
passed := true
for file, stat := range status {
if stat.Staging != git.Unmodified || stat.Worktree != git.Unmodified {
log.Printf("Changed file: %s\n", file)
passed = false
}
if stat.Worktree == git.Untracked {
log.Printf("Untracked file: %s\n", file)
passed = false
}
}
if !passed {
return fmt.Errorf("uncommitted changes or untracked files found")
} else {
log.Println("No uncommitted changes or untracked files.")
}
}
return nil
},
}
if err := app.Run(context.Background(), os.Args); err != nil {
log.Fatal(err)
}
}