-
Notifications
You must be signed in to change notification settings - Fork 51
/
validate_source_cmd.go
59 lines (53 loc) · 1.32 KB
/
validate_source_cmd.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
package app
import (
"runtime"
"strconv"
"github.com/cashapp/hermit"
"github.com/cashapp/hermit/errors"
"github.com/cashapp/hermit/manifest"
"github.com/cashapp/hermit/platform"
"github.com/cashapp/hermit/sources"
"github.com/cashapp/hermit/state"
"github.com/cashapp/hermit/ui"
)
type validateSourceCmd struct {
Source string `arg:"" optional:"" name:"source" help:"The manifest source to validate."`
}
func (g *validateSourceCmd) Run(l *ui.UI, env *hermit.Env, sta *state.State) error {
var (
srcs *sources.Sources
err error
merrors manifest.ManifestErrors
)
if env != nil && g.Source == "" {
merrors, err = env.ValidateManifests(l)
if err != nil {
return errors.WithStack(err)
}
} else {
srcs, err = sources.ForURIs(l, sta.SourcesDir(), "", []string{g.Source})
if err != nil {
return errors.WithStack(err)
}
resolver, err := manifest.New(srcs, manifest.Config{
State: sta.Root(),
Platform: platform.Platform{
OS: runtime.GOOS,
Arch: runtime.GOARCH,
},
})
if err != nil {
return errors.WithStack(err)
}
err = resolver.LoadAll()
if err != nil {
return errors.WithStack(err)
}
}
if len(merrors) > 0 {
merrors.LogErrors(l)
return errors.New("the source had " + strconv.Itoa(len(merrors)) + " broken manifest files")
}
l.Infof("No errors found")
return nil
}