Skip to content

Commit

Permalink
feat(output): add --stdout.iterations option
Browse files Browse the repository at this point in the history
  • Loading branch information
takuo committed Jan 8, 2024
1 parent 39b13e1 commit a9ebe24
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion output/stdout.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"reflect"
"strings"
"sync"
"sync/atomic"
"time"

"github.com/northeye/chissoku/types"
Expand All @@ -16,6 +17,10 @@ import (
// Stdout outputter for Stdout
type Stdout struct {
Base
Iterations int64 `help:"Inavtive on maximum iterations INT"`

// iteration counter
count atomic.Int64

// close
close func()
Expand Down Expand Up @@ -85,5 +90,14 @@ func (s *Stdout) write(d *types.Data) {
slog.Error("json.Marshal", "error", err, "outputter", s.Name())
return
}
fmt.Println(string(b))
if s.Iterations <= 0 {
fmt.Println(string(b))
return
}
if i := s.count.Add(1); i <= s.Iterations {
fmt.Println(string(b))
if i == s.Iterations {
s.cancel()
}
}
}

0 comments on commit a9ebe24

Please sign in to comment.