diff --git a/cmd/lint.go b/cmd/lint.go index 6dde2c48d..33bd485fb 100644 --- a/cmd/lint.go +++ b/cmd/lint.go @@ -3,14 +3,19 @@ package cmd import ( "fmt" + "github.com/odpf/meteor/agent" + "github.com/odpf/meteor/metrics" + "github.com/odpf/meteor/recipe" + "github.com/odpf/meteor/registry" "github.com/odpf/salt/log" + "github.com/odpf/salt/term" "github.com/spf13/cobra" ) // LintCmd creates a command object for linting recipes -func LintCmd(lg log.Logger) *cobra.Command { - cmd := &cobra.Command{ +func LintCmd(lg log.Logger, mt *metrics.StatsdMonitor) *cobra.Command { + return &cobra.Command{ Use: "lint [path]", Aliases: []string{"l"}, Args: cobra.ExactValidArgs(1), @@ -19,9 +24,28 @@ func LintCmd(lg log.Logger) *cobra.Command { Annotations: map[string]string{ "group:core": "true", }, - Run: func(cmd *cobra.Command, args []string) { - fmt.Println("Validating recipe...") + RunE: func(cmd *cobra.Command, args []string) error { + + cs := term.NewColorScheme() + runner := agent.NewAgent(registry.Extractors, registry.Processors, registry.Sinks, mt, lg) + + recipes, err := recipe.NewReader().Read(args[0]) + if err != nil { + return err + } + + if len(recipes) == 0 { + fmt.Println(cs.Yellowf("no recipe found in [%s]", args[0])) + return nil + } + + for _, recipe := range recipes { + if err := runner.Validate(recipe); err != nil { + lg.Error(err.Error()) + continue + } + } + return nil }, } - return cmd } diff --git a/cmd/list.go b/cmd/list.go index 677daadc2..743cb6313 100644 --- a/cmd/list.go +++ b/cmd/list.go @@ -23,6 +23,7 @@ func ListCmd(lg log.Logger) *cobra.Command { cmd.AddCommand(ListExtCmd()) cmd.AddCommand(ListSinksCmd()) cmd.AddCommand(ListProccCmd()) + return cmd } @@ -32,6 +33,9 @@ func ListExtCmd() *cobra.Command { Use: "extractors", Example: "meteor list extractors", Short: "List available extractors", + Annotations: map[string]string{ + "group:core": "true", + }, Run: func(cmd *cobra.Command, args []string) { extractors := registry.Extractors.List() fmt.Printf(" \nShowing %d of %d extractors\n \n", len(extractors), len(extractors)) @@ -47,6 +51,9 @@ func ListSinksCmd() *cobra.Command { Use: "sinks", Example: "meteor list sinks", Short: "List available sinks", + Annotations: map[string]string{ + "group:core": "true", + }, Run: func(cmd *cobra.Command, args []string) { sinks := registry.Sinks.List() fmt.Printf(" \nShowing %d of %d sinks\n \n", len(sinks), len(sinks)) @@ -62,6 +69,9 @@ func ListProccCmd() *cobra.Command { Use: "processors", Example: "meteor list processors", Short: "List available processors", + Annotations: map[string]string{ + "group:core": "true", + }, Run: func(cmd *cobra.Command, args []string) { processors := registry.Processors.List() fmt.Printf(" \nShowing %d of %d processors\n \n", len(processors), len(processors)) diff --git a/cmd/root.go b/cmd/root.go index cff632901..b3fa58f33 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -36,11 +36,11 @@ func New(lg log.Logger, mt *metrics.StatsdMonitor) *cobra.Command { cmd.SetUsageFunc(RootUsageFunc) cmd.SetFlagErrorFunc(RootFlagErrorFunc) - cmd.AddCommand(RunCmd(lg, mt)) cmd.AddCommand(GenCmd(lg)) cmd.AddCommand(ListCmd(lg)) - cmd.AddCommand(LintCmd(lg)) cmd.AddCommand(InfoCmd(lg)) + cmd.AddCommand(RunCmd(lg, mt)) + cmd.AddCommand(LintCmd(lg, mt)) return cmd }