Skip to content

Commit 80ab5a4

Browse files
committed
feat: improve usage guide for run and lint command
1 parent 4a976c9 commit 80ab5a4

File tree

7 files changed

+106
-25
lines changed

7 files changed

+106
-25
lines changed

agent/agent.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func NewAgent(ef *registry.ExtractorFactory, pf *registry.ProcessorFactory, sf *
3737
func (r *Agent) Validate(rcp recipe.Recipe) (errs []error) {
3838
ext, err := r.extractorFactory.Get(rcp.Source.Type)
3939
if err != nil {
40-
errs = append(errs, errors.Wrapf(err, "could not find %s (%s)", rcp.Source.Type, plugins.PluginTypeExtractor))
40+
errs = append(errs, errors.Wrapf(err, "invalid config for %s (%s)", rcp.Source.Type, plugins.PluginTypeExtractor))
4141
} else {
4242
err = ext.Validate(rcp.Source.Config)
4343
if err != nil {
@@ -48,7 +48,7 @@ func (r *Agent) Validate(rcp recipe.Recipe) (errs []error) {
4848
for _, s := range rcp.Sinks {
4949
sink, err := r.sinkFactory.Get(s.Name)
5050
if err != nil {
51-
errs = append(errs, errors.Wrapf(err, "could not find %s (%s)", s.Name, plugins.PluginTypeSink))
51+
errs = append(errs, errors.Wrapf(err, "invalid config for %s (%s)", rcp.Source.Type, plugins.PluginTypeExtractor))
5252
continue
5353
}
5454
err = sink.Validate(s.Config)
@@ -60,7 +60,7 @@ func (r *Agent) Validate(rcp recipe.Recipe) (errs []error) {
6060
for _, p := range rcp.Processors {
6161
procc, err := r.processorFactory.Get(p.Name)
6262
if err != nil {
63-
errs = append(errs, errors.Wrapf(err, "could not find %s (%s)", p.Name, plugins.PluginTypeProcessor))
63+
errs = append(errs, errors.Wrapf(err, "invalid config for %s (%s)", rcp.Source.Type, plugins.PluginTypeExtractor))
6464
continue
6565
}
6666
err = procc.Validate(p.Config)

cmd/info.go

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cmd
33
import (
44
"fmt"
55

6+
"github.com/MakeNowJust/heredoc"
67
"github.com/charmbracelet/glamour"
78
"github.com/odpf/meteor/registry"
89
"github.com/odpf/salt/log"
@@ -28,10 +29,17 @@ func InfoCmd(lg log.Logger) *cobra.Command {
2829
// InfoSinkCmd creates a command object for listing sinks
2930
func InfoSinkCmd() *cobra.Command {
3031
cmd := &cobra.Command{
31-
Use: "sink <name>",
32-
Example: "meteor info sink console",
33-
Short: "Vew an sink information",
34-
Args: cobra.ExactArgs(1),
32+
Use: "sink <name>",
33+
Short: "Vew sink information",
34+
Long: heredoc.Doc(`
35+
View sink information.
36+
37+
The list of supported sinks is available via the 'meteor list sinks' command.
38+
`),
39+
Example: heredoc.Doc(`
40+
$ meteor info sink console
41+
`),
42+
Args: cobra.ExactArgs(1),
3543
Annotations: map[string]string{
3644
"group:core": "true",
3745
},
@@ -51,10 +59,17 @@ func InfoSinkCmd() *cobra.Command {
5159
// InfoExtCmd creates a command object for listing extractors
5260
func InfoExtCmd() *cobra.Command {
5361
cmd := &cobra.Command{
54-
Use: "extractor <name>",
55-
Example: "meteor info extractor kafka",
56-
Short: "Vew extractor information",
57-
Args: cobra.ExactArgs(1),
62+
Use: "extractor <name>",
63+
Short: "Vew extractor information",
64+
Long: heredoc.Doc(`
65+
View sink information.
66+
67+
The list of supported extractors is available via the 'meteor list extractors' command.
68+
`),
69+
Example: heredoc.Doc(`
70+
$ meteor info sink console
71+
`),
72+
Args: cobra.ExactArgs(1),
5873
Annotations: map[string]string{
5974
"group:core": "true",
6075
},
@@ -73,10 +88,17 @@ func InfoExtCmd() *cobra.Command {
7388
// InfoProccCmd creates a command object for listing processors
7489
func InfoProccCmd() *cobra.Command {
7590
cmd := &cobra.Command{
76-
Use: "processor <name>",
77-
Example: "meteor info processor enrich",
78-
Short: "Vew processor information",
79-
Args: cobra.ExactArgs(1),
91+
Use: "processor <name>",
92+
Short: "Vew processor information",
93+
Long: heredoc.Doc(`
94+
View processor information.
95+
96+
The list of supported processors is available via the 'meteor list processors' command.
97+
`),
98+
Example: heredoc.Doc(`
99+
$ meteor info sink console
100+
`),
101+
Args: cobra.ExactArgs(1),
80102
Annotations: map[string]string{
81103
"group:core": "true",
82104
},

cmd/lint.go

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cmd
33
import (
44
"fmt"
55

6+
"github.com/MakeNowJust/heredoc"
67
"github.com/odpf/meteor/agent"
78
"github.com/odpf/meteor/metrics"
89
"github.com/odpf/meteor/recipe"
@@ -19,8 +20,22 @@ func LintCmd(lg log.Logger, mt *metrics.StatsdMonitor) *cobra.Command {
1920
Use: "lint [path]",
2021
Aliases: []string{"l"},
2122
Args: cobra.ExactValidArgs(1),
22-
Example: "meteor lint recipe.yaml",
23-
Short: "Validate recipes.",
23+
Short: "Validate recipes",
24+
Long: heredoc.Doc(`
25+
Validate specified recipes.
26+
27+
Linters are run on the recipe files in the specified path.
28+
If no path is specified, the current directory is used.
29+
`),
30+
Example: heredoc.Doc(`
31+
$ meteor lint recipe.yml
32+
33+
# lint all recipes in the specified directory
34+
$ meteor lint _recipes/
35+
36+
# lint all recipes in the current directory
37+
$ meteor lint .
38+
`),
2439
Annotations: map[string]string{
2540
"group:core": "true",
2641
},
@@ -36,20 +51,31 @@ func LintCmd(lg log.Logger, mt *metrics.StatsdMonitor) *cobra.Command {
3651

3752
if len(recipes) == 0 {
3853
fmt.Println(cs.Yellowf("no recipe found in [%s]", args[0]))
54+
fmt.Println(cs.Blue("\nUse 'meteor gen recipe' to generate a new recipe."))
3955
return nil
4056
}
4157

58+
report := []string{""}
59+
var success = 0
60+
var failures = 0
4261
for _, recipe := range recipes {
4362
errs := runner.Validate(recipe)
4463
if len(errs) > 0 {
45-
// Print errors
4664
for _, err := range errs {
4765
lg.Error(err.Error())
4866
}
67+
report = append(report, fmt.Sprint(cs.FailureIcon(), cs.Redf(" %d errors found is recipe %s", len(errs), recipe.Name)))
68+
failures++
4969
continue
5070
}
51-
fmt.Println(cs.Greenf("recipe [%s] is valid", recipe.Name))
71+
report = append(report, fmt.Sprint(cs.SuccessIcon(), cs.Greenf(" 0 error found in recipe %s", recipe.Name)))
72+
success++
73+
}
74+
75+
for _, line := range report {
76+
fmt.Println(line)
5277
}
78+
fmt.Printf("Total: %d, Success: %d, Failures: %d\n", len(recipes), success, failures)
5379
return nil
5480
},
5581
}

cmd/run.go

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cmd
33
import (
44
"fmt"
55

6+
"github.com/MakeNowJust/heredoc"
67
"github.com/odpf/meteor/agent"
78
"github.com/odpf/meteor/metrics"
89
"github.com/odpf/meteor/recipe"
@@ -15,10 +16,29 @@ import (
1516
// RunCmd creates a command object for the "run" action.
1617
func RunCmd(lg log.Logger, mt *metrics.StatsdMonitor) *cobra.Command {
1718
return &cobra.Command{
18-
Use: "run [COMMAND]",
19-
Example: "meteor run recipe.yaml",
20-
Short: "Run meteor for provided recipes.",
21-
Args: cobra.ExactArgs(1),
19+
Use: "run [COMMAND]",
20+
Short: "Run meteor for specified recipes.",
21+
Long: heredoc.Doc(`
22+
Run meteor for specified recipes.
23+
24+
A recipe is a set of instructions and configurations defined by user,
25+
and in Meteor they are used to define how metadata will be collected.
26+
27+
If a recipe file is provided, recipe will be
28+
executed as a single recipe.
29+
If a recipe directory is provided, recipes will
30+
be executed as a group of recipes.
31+
`),
32+
Example: heredoc.Doc(`
33+
$ meteor run recipe.yml
34+
35+
# run all recipes in the specified directory
36+
$ meteor run _recipes/
37+
38+
# run all recipes in the current directory
39+
$ meteor lint .
40+
`),
41+
Args: cobra.ExactArgs(1),
2242
Annotations: map[string]string{
2343
"group:core": "true",
2444
},
@@ -33,19 +53,32 @@ func RunCmd(lg log.Logger, mt *metrics.StatsdMonitor) *cobra.Command {
3353
}
3454

3555
if len(recipes) == 0 {
36-
fmt.Println(cs.Yellowf("no recipe found in [%s]", args[0]))
56+
fmt.Println(cs.WarningIcon(), cs.Yellowf(" no recipe found in [%s]", args[0]))
3757
return nil
3858
}
3959

60+
report := []string{""}
61+
var success = 0
62+
var failures = 0
63+
4064
runs := runner.RunMultiple(recipes)
4165
for _, run := range runs {
4266
lg.Debug("recipe details", "recipe", run.Recipe)
4367
if run.Error != nil {
4468
lg.Error(run.Error.Error(), "recipe", run.Recipe.Name)
69+
report = append(report, fmt.Sprint(cs.FailureIcon(), cs.Redf(" failed to run recipe %s", run.Recipe.Name)))
70+
failures++
4571
continue
4672
}
47-
lg.Info("success", "recipe", run.Recipe.Name)
73+
success++
74+
report = append(report, fmt.Sprint(cs.SuccessIcon(), cs.Greenf(" successfully ran recipe `%s`", run.Recipe.Name)))
4875
}
76+
77+
for _, line := range report {
78+
fmt.Println(line)
79+
}
80+
fmt.Printf("Total: %d, Success: %d, Failures: %d\n", len(recipes), success, failures)
81+
4982
return nil
5083
},
5184
}
File renamed without changes.

0 commit comments

Comments
 (0)