Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ OUTER_LOOP:

// Flush after each batch to make file-following work as expected
if err := stdout.Flush(); err != nil {
logger.Fatal(helpers.ExitCodeInvalidUsage, err)
logger.Fatal(helpers.ExitCodeOutputError, err)
}
}

// Final flush
if err := stdout.Flush(); err != nil {
logger.Fatal(helpers.ExitCodeInvalidUsage, err)
logger.Fatal(helpers.ExitCodeOutputError, err)
}

// Summary
Expand Down
3 changes: 2 additions & 1 deletion cmd/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"os"
"rare/cmd/helpers"
"rare/pkg/testutil"
"testing"

Expand Down Expand Up @@ -91,7 +92,7 @@ func TestFilterFromStdin(t *testing.T) {
func TestFilterFileNotExist(t *testing.T) {
out, eout, err := testCommandCapture(filterCommand(), `-m (\d+) -e "{1}" testdata/no-exist.txt`)
assert.Error(t, err)
assert.Equal(t, 2, err.(cli.ExitCoder).ExitCode())
assert.Equal(t, helpers.ExitCodeReadError, err.(cli.ExitCoder).ExitCode())
assert.Equal(t, "", out)
assert.Equal(t, "Matched: 0 / 0\nRead errors", eout)
}
Expand Down
4 changes: 3 additions & 1 deletion cmd/helpers/exitCodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
const (
ExitCodeNoData = 1
ExitCodeInvalidUsage = 2
ExitCodeReadError = 3
ExitCodeOutputError = 4
)

type (
Expand All @@ -23,7 +25,7 @@ type (

func DetermineErrorState(b BatcherErrors, e ExtractorSummary, agg AggregationErrors) error {
if b.ReadErrors() > 0 {
return cli.Exit("Read errors", ExitCodeInvalidUsage)
return cli.Exit("Read errors", ExitCodeReadError)
}
if agg != nil && agg.ParseErrors() > 0 {
return cli.Exit("Parse errors", ExitCodeInvalidUsage)
Expand Down
6 changes: 4 additions & 2 deletions cmd/helpers/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ func BuildVTermFromArguments(c *cli.Context) multiterm.MultilineTerm {
func TryWriteCSV[T any](c *cli.Context, agg T, writer func(w csv.CSV, agg T) error) error {
if filename := c.String(CSVFlag.Name); filename != "" {
if w, err := csv.OpenCSV(filename); err != nil {
return err
return cli.Exit(err, ExitCodeOutputError)
} else {
defer w.Close()
return writer(w, agg)
if err := writer(w, agg); err != nil {
return cli.Exit(err, ExitCodeOutputError)
}
}
}
return nil
Expand Down
1 change: 1 addition & 0 deletions cmd/helpers/output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func TestTryWriteCSV(t *testing.T) {
agg := aggregation.NewCounter()
return TryWriteCSV(ctx, agg, csv.WriteCounter)
}
app.ExitErrHandler = func(cCtx *cli.Context, err error) {}
assert.NoError(t, app.Run([]string{""}))
assert.NoError(t, app.Run([]string{"", "--csv", "-"}))
assert.Error(t, app.Run([]string{"", "--csv", "/!@#bad-filename"}))
Expand Down
Loading