7
7
"flag"
8
8
"fmt"
9
9
"os"
10
+ "regexp"
10
11
"text/template"
11
12
"time"
12
13
)
@@ -26,12 +27,14 @@ type line struct {
26
27
Total string `json:"total,omitempty"`
27
28
Text string `json:"text,omitempty"`
28
29
Previous string `json:"previous,omitempty"`
30
+ Start string `json:"start,omitempty"`
29
31
}
30
32
31
33
type configuration struct {
32
34
timeFormat string // -timeformat="..."
33
35
template string // -template="..."
34
36
plain bool // -plain
37
+ start string // -start="..."
35
38
version string
36
39
previous bool
37
40
}
@@ -90,6 +93,7 @@ func init() {
90
93
flag .StringVar (& config .template , "template" , "" , "go template (https://golang.org/pkg/text/template)" )
91
94
flag .StringVar (& config .timeFormat , "timeformat" , "RFC3339" , timeFormatsHelp ())
92
95
flag .BoolVar (& config .plain , "plain" , false , "-template='{{.Time}} +{{.DeltaNanos}} {{.Text}}'" )
96
+ flag .StringVar (& config .start , "start" , "" , "a regex pattern. if given, only lines matching it (re)start the stopwatch" )
93
97
flag .BoolVar (& config .previous , "previous" , false , "include previous line" )
94
98
flag .Parse ()
95
99
if knownFormat , ok := timeFormats [config .timeFormat ]; ok {
@@ -113,6 +117,10 @@ func main() {
113
117
first := now
114
118
previous := ""
115
119
i := uint64 (0 )
120
+ var start * regexp.Regexp
121
+ if config .start != "" {
122
+ start = regexp .MustCompile (config .start )
123
+ }
116
124
for scanner .Scan () {
117
125
now = time .Now ()
118
126
delta := now .Sub (last )
@@ -137,7 +145,10 @@ func main() {
137
145
if err := printer (& line ); err != nil {
138
146
fmt .Fprintln (os .Stderr , "output error:" , err )
139
147
}
140
- last = now
148
+ if start != nil && start .MatchString (line .Text ) {
149
+ last = now
150
+ line .Start = line .Text
151
+ }
141
152
i ++
142
153
}
143
154
0 commit comments