aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorRasmus Dahlberg <rasmus@rgdd.se>2023-03-26 18:31:10 +0200
committerRasmus Dahlberg <rasmus@rgdd.se>2023-03-26 18:31:10 +0200
commitf14b185dfe1fed4fdc951b91f3338359538c4832 (patch)
tree07af788813c2a18ea07a477583fd23e9a8a63ffc /main.go
parentba6dd77c216149d663ea095ba4e5d77fcf78501e (diff)
Add option to specify [START,END) lines
Diffstat (limited to 'main.go')
-rw-r--r--main.go22
1 files changed, 13 insertions, 9 deletions
diff --git a/main.go b/main.go
index e4d2027..55e7989 100644
--- a/main.go
+++ b/main.go
@@ -90,11 +90,11 @@ func main() {
log.Printf("INFO: generating work\n")
nextLine, readAll := workGenerator(ctx, opts, fp, questionCh)
if !readAll {
- warn := fmt.Sprintf("only read up until line %d", nextLine)
- if opts.NextLine != 0 {
- warn += fmt.Sprintf(" (line %d relative to start)", nextLine-opts.NextLine)
+ notice := fmt.Sprintf("only read up until line %d", nextLine)
+ if opts.StartLineInclusive != 0 {
+ notice += fmt.Sprintf(" (line %d relative to start)", nextLine-opts.StartLineInclusive)
}
- log.Printf("NOTICE: %s\n", warn)
+ log.Printf("NOTICE: %s\n", notice)
}
}
@@ -218,18 +218,18 @@ func workGenerator(ctx context.Context, opts options.Options, fp *os.File, quest
scanner.Buffer(buf, opts.MaxFileBuffer*1024*1024)
nextLine := int64(0)
- if opts.NextLine > nextLine {
+ if opts.StartLineInclusive > nextLine {
for scanner.Scan() {
+ nextLine++
select {
case <-ctx.Done():
return nextLine, false
default:
}
- if nextLine+1 == opts.NextLine {
+ if nextLine == opts.StartLineInclusive {
break
}
- nextLine++
}
}
@@ -238,8 +238,12 @@ func workGenerator(ctx context.Context, opts options.Options, fp *os.File, quest
startTime := time.Now().Unix()
latestTime := startTime
- latestCount := opts.NextLine
+ latestCount := opts.StartLineInclusive
for scanner.Scan() {
+ if opts.EndLineExclusive > 0 && nextLine == opts.EndLineExclusive {
+ break
+ }
+
select {
case <-ctx.Done():
return nextLine, false
@@ -247,7 +251,7 @@ func workGenerator(ctx context.Context, opts options.Options, fp *os.File, quest
now := time.Now().Unix()
log.Printf("INFO: currently %.1f sites/s, %.1f sites/s since start, at line %d\n",
float64(nextLine-latestCount)/float64(now-latestTime),
- float64(nextLine-opts.NextLine)/float64(now-startTime),
+ float64(nextLine-opts.StartLineInclusive)/float64(now-startTime),
nextLine,
)