Moved flag-checking after flag.Parse()
This commit is contained in:
14
main.go
14
main.go
@@ -15,6 +15,8 @@ import (
|
||||
|
||||
const CONCAT rune = '~'
|
||||
|
||||
var notDotChars []rune
|
||||
|
||||
func isOperator(c rune) bool {
|
||||
if c == '+' || c == '?' || c == '*' || c == '|' || c == CONCAT {
|
||||
return true
|
||||
@@ -388,11 +390,17 @@ func main() {
|
||||
// 1. Without '-v': Prints only matches. Prints a newline after every match.
|
||||
// 2. With '-v': Substitutes all matches with empty string.
|
||||
onlyFlag := flag.Bool("o", false, "Print only colored content. Overrides -l.")
|
||||
lineFlag := flag.Bool("l", false, "Only print lines with a match (or with no matches, if -v is enabled (similar to grep's default")
|
||||
multiLineFLag := flag.Bool("t", false, "Multi-line mode. Treats newline just like any character.")
|
||||
lineFlag := flag.Bool("l", false, "Only print lines with a match (or with no matches, if -v is enabled). Similar to grep's default.")
|
||||
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.")
|
||||
flag.Parse()
|
||||
|
||||
// In multi-line mode, 'dot' metacharacter also matches newline
|
||||
if !(*multiLineFlag) {
|
||||
notDotChars = []rune{'\n'}
|
||||
} else {
|
||||
notDotChars = []rune{}
|
||||
}
|
||||
// -l and -o are mutually exclusive: -o overrides -l
|
||||
if *onlyFlag {
|
||||
*lineFlag = false
|
||||
@@ -424,7 +432,7 @@ func main() {
|
||||
if linesRead {
|
||||
break
|
||||
}
|
||||
if !(*multiLineFLag) {
|
||||
if !(*multiLineFlag) {
|
||||
// Read every string from stdin until we encounter an error. If the error isn't EOF, panic.
|
||||
test_str, err = reader.ReadString('\n')
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user