Documentation
¶
Overview ¶
Package argf provides a simple way of reading line-by-line from either files given as command-line arguments or, if none were given, from stdin.
The interface resembles bufio.Scanner.
This package provides a convenient way of handling input for command-line utilities. For instance, here is a simple implementation of the Unix utility 'cat':
for argf.Scan() { fmt.Println(argf.String()) } if err := argf.Error(); err != nil { fmt.Println(err) os.Exit(1) }
If flags are required, you can call Init(flag.Args()) after flag parsing but before any other argf calls to initialize argf with the non-flag arguments given in the command-line (presumably filenames).
Multiple goroutines should not call any of the functions in argf concurrently.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Bytes ¶
func Bytes() []byte
Bytes returns the current line as a []byte without the trailing newline. It panics unless preceeded by a call to Scan that returned true. Bytes may be called multiple times consecutively but returns the same line each time.
func Error ¶
func Error() error
Error returns the error that caused Scan to return false, unless it was an io.EOF, in which case Error returns nil.
func Init ¶
func Init(args []string)
Init initializes argf's state using some filename arguments. If args is empty, argf uses stdin instead of files. Without calling Init(), argf initializes itself the first time Scan is called, using os.Args[1:] (ignoring the program name).
func Scan ¶
func Scan() bool
Scan reads the next line from either os.Stdin or the current file in os.Args, as described in the package documentation. If the current file has been exhausted, Scan attempts to open the next file in os.Args, if there is one. If there are no more lines to be read from os.Stdin or any files, or if Scan encounters an error, false is returned. Otherwise, true is returned and the line is available to be accessed by String or Bytes.
Types ¶
This section is empty.