Explain successful parsers only (#2063)

* Add option to filter down explain to successful parsers useful for me who has every collection installed

* Altered naming conventions so it makes more sense when reading
This commit is contained in:
Laurence Jones 2023-02-24 13:49:17 +00:00 committed by GitHub
parent 8acce4637a
commit 75d8b821ff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 3 deletions

View file

@ -50,6 +50,12 @@ func runExplain(cmd *cobra.Command, args []string) error {
return err
}
opts.ShowNotOkParsers, err = flags.GetBool("only-successful-parsers")
opts.ShowNotOkParsers = !opts.ShowNotOkParsers
if err != nil {
return err
}
crowdsec, err := flags.GetString("crowdsec")
if err != nil {
return err
@ -182,6 +188,7 @@ tail -n 5 myfile.log | cscli explain --type nginx -f -
flags.StringP("type", "t", "", "Type of the acquisition to test")
flags.BoolP("verbose", "v", false, "Display individual changes")
flags.Bool("failures", false, "Only show failed lines")
flags.Bool("only-successful-parsers", false, "Only show successful parsers")
flags.String("crowdsec", "crowdsec", "Path to crowdsec")
return cmdExplain

View file

@ -299,8 +299,9 @@ func LoadParserDump(filepath string) (*ParserResults, error) {
}
type DumpOpts struct {
Details bool
SkipOk bool
Details bool
SkipOk bool
ShowNotOkParsers bool
}
func DumpTree(parser_results ParserResults, bucket_pour BucketPourInfo, opts DumpOpts) {
@ -445,7 +446,7 @@ func DumpTree(parser_results ParserResults, bucket_pour BucketPourInfo, opts Dum
if opts.Details {
fmt.Print(detailsDisplay)
}
} else {
} else if opts.ShowNotOkParsers {
fmt.Printf("\t%s\t%s %s %s\n", presep, sep, emoji.RedCircle, parser)
}