Started working on file arguments - stdin is used if arg is "-"
This commit is contained in:
14
cmd/main.go
14
cmd/main.go
@@ -70,12 +70,24 @@ func main() {
|
||||
}
|
||||
var re string
|
||||
re = flag.Args()[0]
|
||||
var inputFile *os.File
|
||||
if len(flag.Args()) == 1 || flag.Args()[1] == "-" { // Either no file argument, or file argument is "-"
|
||||
inputFile = os.Stdin
|
||||
} else {
|
||||
var err error
|
||||
inputFile, err = os.Open(flag.Args()[1])
|
||||
if err != nil {
|
||||
fmt.Printf("%s: No such file or directory\n", flag.Args()[1])
|
||||
os.Exit(2)
|
||||
}
|
||||
}
|
||||
|
||||
var test_str string
|
||||
var err error
|
||||
var linesRead bool // Whether or not we have read the lines in the file
|
||||
lineNum := 0 // Current line number
|
||||
// Create reader for stdin and writer for stdout
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
reader := bufio.NewReader(inputFile)
|
||||
out := bufio.NewWriter(os.Stdout)
|
||||
|
||||
regComp, err := reg.Compile(re, flagsToCompile...)
|
||||
|
Reference in New Issue
Block a user