-
Notifications
You must be signed in to change notification settings - Fork 3
/
cmd.go
72 lines (61 loc) · 1.82 KB
/
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
60
61
62
63
64
65
66
67
68
69
70
71
72
package catalogcmd
import (
"context"
"flag"
"os"
"github.com/peterbourgon/ff/v3/ffcli"
"github.com/sensu/catalog-api/internal/commands/rootcmd"
)
var (
defaultIntegrationsDirName = "integrations"
defaultRepoDir = "."
defaultTempDir = os.TempDir()
defaultSnapshot = false
defaultWatchMode = false
defaultApiURL = "http://localhost:8080"
)
type Config struct {
rootConfig rootcmd.Config
repoDir string
tempDir string
integrationsDirName string
snapshot bool
watch bool
port int
apiURL string
}
func New(rootConfig rootcmd.Config) *ffcli.Command {
cfg := Config{
rootConfig: rootConfig,
}
fs := flag.NewFlagSet("catalog-api catalog", flag.ExitOnError)
cfg.RegisterFlags(fs)
return &ffcli.Command{
Name: "catalog",
ShortUsage: "catalog-api catalog [flags] <subcommand> [flags]",
ShortHelp: "Validate a Catalog and its integrations",
FlagSet: fs,
Exec: cfg.Exec,
Subcommands: []*ffcli.Command{
cfg.GenerateCommand(),
cfg.ValidateCommand(),
cfg.ServerCommand(),
cfg.PreviewCommand(),
},
}
}
func (c *Config) RegisterFlags(fs *flag.FlagSet) {
// register catalog flags
c.RegisterCatalogFlags(fs)
// register global flags
c.rootConfig.RegisterFlags(fs)
}
func (c *Config) RegisterCatalogFlags(fs *flag.FlagSet) {
fs.StringVar(&c.repoDir, "repo-dir", defaultRepoDir, "path to the catalog repository")
fs.StringVar(&c.integrationsDirName, "integrations-dir-name", defaultIntegrationsDirName, "path to the directory containing namespaced integrations")
}
func (c *Config) Exec(context.Context, []string) error {
// The catalog command has no meaning, so if it gets executed,
// display the usage text to the user instead.
return flag.ErrHelp
}