Documentation
¶
Overview ¶
Package argvreader makes it a bit less painful to write filter programs in Go especially for Perl programmers.
Description ¶
The `argvreader.Reader` behaves just like Perl's `<ARGV>`, that reads lines from one file after another if file list is given in command line arguments, reads from STDIN otherwise. This may be useful to implement UNIX-style filter command, like gzip or grep.
Example
import argvreader "github.com/Maki-Daisuke/go-argvreader"
func main(){
r := argvreader.New()
b := bufio.NewReader(r)
for{
line, err := b.ReadString('\n')
if err != nil {
if err == io.EOF {
break
}
panic(err)
}
do_something(line)
}
}
Then, in your command line:
$ ./main foo bar baz
This reads lines from foo, bar and baz one after another. If no argument is given:
$ ./main
This reads lines from STDIN instead.
You can pass file list manually, of course:
import flags "github.com/jessevdk/go-flags"
var opts struct { ... }
args, err := flags.ParseArgs(&opts, args)
r := argvreader.NewReader(args)
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
Click to show internal directories.
Click to hide internal directories.