Fixed bug where I checked if flag was enabled before calling flag.Parse()

master
Aadhavan Srinivasan 3 weeks ago
parent 0b84806fc4
commit 0956dddd81

@ -23,16 +23,17 @@ func main() {
multiLineFlag := flag.Bool("t", false, "Multi-line mode. Treats newline just like any character.") multiLineFlag := flag.Bool("t", false, "Multi-line mode. Treats newline just like any character.")
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.")
if *caseInsensitiveFlag {
flagsToCompile = append(flagsToCompile, RE_CASE_INSENSITIVE)
}
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()
// These flags have to be passed to the Compile function
if *multiLineFlag { if *multiLineFlag {
flagsToCompile = append(flagsToCompile, RE_MULTILINE) flagsToCompile = append(flagsToCompile, RE_MULTILINE)
} }
if *caseInsensitiveFlag {
flagsToCompile = append(flagsToCompile, RE_CASE_INSENSITIVE)
}
// -l and -o are mutually exclusive: -o overrides -l // -l and -o are mutually exclusive: -o overrides -l
if *onlyFlag { if *onlyFlag {

Loading…
Cancel
Save