Started working on line number flag
This commit is contained in:
@@ -27,6 +27,7 @@ func main() {
|
|||||||
printMatchesFlag := flag.Bool("p", false, "Prints start and end index of each match. Can only be used with '-t' for multi-line mode.")
|
printMatchesFlag := flag.Bool("p", false, "Prints start and end index of each match. Can only be used with '-t' for multi-line mode.")
|
||||||
caseInsensitiveFlag := flag.Bool("i", false, "Case-insensitive. Disregard the case of all characters.")
|
caseInsensitiveFlag := flag.Bool("i", false, "Case-insensitive. Disregard the case of all characters.")
|
||||||
recursiveFlag := flag.Bool("r", false, "Recursively search all files in the given directory.")
|
recursiveFlag := flag.Bool("r", false, "Recursively search all files in the given directory.")
|
||||||
|
lineNumFlag := flag.Bool("n", false, "For each line with a match, print the line number. Implies -l.")
|
||||||
matchNum := flag.Int("m", 0, "Print the match with the given index. Eg. -m 3 prints the third match.")
|
matchNum := flag.Int("m", 0, "Print the match with the given index. Eg. -m 3 prints the third match.")
|
||||||
substituteText := flag.String("s", "", "Substitute the contents of each match with the given string. Overrides -o and -v")
|
substituteText := flag.String("s", "", "Substitute the contents of each match with the given string. Overrides -o and -v")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
@@ -110,9 +111,6 @@ func main() {
|
|||||||
reader := bufio.NewReader(inputFile)
|
reader := bufio.NewReader(inputFile)
|
||||||
linesRead = false
|
linesRead = false
|
||||||
for true {
|
for true {
|
||||||
if !(*lineFlag) && (!*onlyFlag) {
|
|
||||||
color.New(color.FgMagenta).Fprintf(out, "%s: ", inputFile.Name()) // The filename should be printed for every line, _except_ if we're not printing every line. This is the case with the lineFlag and onlyFlag
|
|
||||||
}
|
|
||||||
if linesRead {
|
if linesRead {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user