Skip to content

Commit

Permalink
feat: add lint command (#195)
Browse files Browse the repository at this point in the history
  • Loading branch information
ravisuhag authored Sep 5, 2021
1 parent 49fc1b4 commit bee59e3
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 7 deletions.
34 changes: 29 additions & 5 deletions cmd/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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
}
10 changes: 10 additions & 0 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func ListCmd(lg log.Logger) *cobra.Command {
cmd.AddCommand(ListExtCmd())
cmd.AddCommand(ListSinksCmd())
cmd.AddCommand(ListProccCmd())

return cmd
}

Expand All @@ -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))
Expand All @@ -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))
Expand All @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit bee59e3

Please sign in to comment.