args

package
v0.1.16 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 11, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package args provides an iterator to scan text lines from multiple sources.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Scan

func Scan(args []string, files []string, optFns ...func(*Scanner)) func(yield func(string, error) bool)

Scan starts scanning for text lines from a string slice, files, or from os.Stdin using a custom Scanner.

This method will supply a sensible Scanner.Filter that trims the returned lines while also skipping empty lines as well as lines starting with "#".

See Scanner.Scan for more information.

Types

type Scanner

type Scanner struct {
	// Filter filters and transforms which lines of text are kept and returned by Scan.
	//
	// By default, the nil value means all lines are returned as-is without any transformation.
	Filter func(string) (string, bool)

	// NoStdin if true will cause Scan to never read from os.Stdin.
	NoStdin bool
}

Scanner produces lines of text from command-line positional arguments and additional sources.

func (*Scanner) Scan

func (s *Scanner) Scan(args []string, files []string) func(yield func(string, error) bool)

Scan starts scanning for text lines from a string slice, files, or from os.Stdin.

The use case for this method comes from passing command-line positional arguments; if "--" exists as one of the arguments, the scanner will start reading from os.Stdin after exhausting args and files.

Similarly, you can also pass a list of files whose content will be parsed as newline-delimited text. Error opening a file will not automatically stop the iterator; it is up to consumer of the iterator to stop or not, but the file will be skipped in case of error.

If both args and files are empty, Scan will automatically scan from os.Stdin unless Scanner.NoStdin is true.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL