Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 29a3a03

Browse files
Add --thread option (default 10)
Limit the concurrent wait groups to avoid too many open files
1 parent d4926af commit 29a3a03

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

‎main.go‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package main
22

33
import (
44
"fmt"
5-
"sync"
65
"errors"
76
"bytes"
87
"io/ioutil"
@@ -11,6 +10,7 @@ import (
1110
"strings"
1211
"regexp"
1312
flags "github.com/jessevdk/go-flags"
13+
"github.com/remeh/sizedwaitgroup"
1414
)
1515

1616
const (
@@ -38,6 +38,7 @@ type fileitem struct {
3838
}
3939

4040
var opts struct {
41+
ThreadCount int ` long:"threads" description:"Set thread concurrency for replacing in multiple files at same time" default:"10"`
4142
Mode string `short:"m" long:"mode" description:"replacement mode - replace: replace match with term; line: replace line with term; lineinfile: replace line with term or if not found append to term to file; template: parse content as golang template, search value have to start uppercase" default:"replace" choice:"replace" choice:"line" choice:"lineinfile" choice:"template"`
4243
ModeIsReplaceMatch bool
4344
ModeIsReplaceLine bool
@@ -347,11 +348,11 @@ func actionProcessFiles(changesets []changeset, fileitems []fileitem) (int) {
347348

348349
results := make(chan changeresult)
349350

350-
varwg sync.WaitGroup
351+
wg :=sizedwaitgroup.New(opts.ThreadCount)
351352

352353
// process file list
353354
for _, file := range fileitems {
354-
wg.Add(1)
355+
wg.Add()
355356
go func(file fileitem, changesets []changeset) {
356357
var (
357358
err error = nil

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /