Skip to content

Commit

Permalink
Add flag to skip lisnes with errors (bad json or plain text in json-s…
Browse files Browse the repository at this point in the history
…tream)
  • Loading branch information
shnellpavel committed Jan 14, 2019
1 parent c897e8f commit d80f2b1
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion jsonstream-cli/cmd/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import (

// FilterCommand represents command to filter stream
type FilterCommand struct {
condition string
condition string
skipErrLines bool
}

// NewFilter constructs FilterCommand
Expand All @@ -26,6 +27,9 @@ func (c *FilterCommand) InitArgs(cmd *kingpin.CmdClause) {
cmd.Flag("condition", "expression with condition").
Required().
StringVar(&c.condition)

cmd.Flag("skip-err-lines", "skips lines that unable to parse").
BoolVar(&c.skipErrLines)
}

// Run handles command execution
Expand Down Expand Up @@ -58,6 +62,10 @@ func (c *FilterCommand) Run(_ *kingpin.ParseContext) error {

resLine, isOk, err := filter.ProcessElem(*filterExpr, line)
if err != nil {
if c.skipErrLines {
continue
}

return errors.Wrap(err, "process line error")
}

Expand Down

0 comments on commit d80f2b1

Please sign in to comment.