Added support for printing specific match indices ('-m' and '-p' flags combined)
This commit is contained in:
10
main.go
10
main.go
@@ -705,8 +705,14 @@ func main() {
|
|||||||
if !(*multiLineFlag) {
|
if !(*multiLineFlag) {
|
||||||
fmt.Fprintf(out, "Line %d:\n", lineNum)
|
fmt.Fprintf(out, "Line %d:\n", lineNum)
|
||||||
}
|
}
|
||||||
for _, idx := range matchIndices {
|
for i, m := range matchIndices {
|
||||||
fmt.Fprintf(out, "%s\n", idx.toString())
|
// Only print a match if:
|
||||||
|
// a. We are _not_ printing just one match
|
||||||
|
// OR
|
||||||
|
// b. We _are_ printing just one match, and this is that match
|
||||||
|
if !matchNumFlagEnabled || (i+1) == *matchNum { // Match indexes start from 1; loop counter starts from 0
|
||||||
|
fmt.Fprintf(out, "%s\n", m.toString())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
err := out.Flush()
|
err := out.Flush()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Reference in New Issue
Block a user