-
Notifications
You must be signed in to change notification settings - Fork 3
/
validate.go
41 lines (32 loc) · 966 Bytes
/
validate.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
package catalogcmd
import (
"context"
"flag"
"fmt"
"github.com/peterbourgon/ff/v3/ffcli"
"github.com/sensu/catalog-api/internal/catalogloader"
)
func (c *Config) ValidateCommand() *ffcli.Command {
fs := flag.NewFlagSet("catalog-api catalog validate", flag.ExitOnError)
// register catalog & global flags
c.RegisterFlags(fs)
return &ffcli.Command{
Name: "validate",
ShortUsage: "catalog-api catalog validate [flags]",
ShortHelp: "Validate a catalog directory and its integrations",
FlagSet: fs,
Exec: c.rootConfig.PreExec(c.execValidate),
}
}
func (c *Config) execValidate(context.Context, []string) error {
loader := catalogloader.NewPathLoader(c.repoDir, c.integrationsDirName)
cm, err := c.newCatalogManager(loader)
if err != nil {
return err
}
// validate the catalog & all its integrations
if err := cm.ValidateCatalog(); err != nil {
return fmt.Errorf("error validating catalog: %w", err)
}
return nil
}