~kota/dprint

8b4608c65f3e2e81cc65308cfa849abde8e03fe0 — Dakota Walsh 1 year, 1 month ago 3dbc3d1
clean up main function

Gave the code block a little breathing room, removed the date + prefix
from the logger, and made the "couldn't find any entries" actually
return an error code.
1 files changed, 10 insertions(+), 2 deletions(-)

M main.go
M main.go => main.go +10 -2
@@ 31,7 31,10 @@ func usage() {
}

func main() {
	// parse arguments in the getopt style
	log.SetPrefix("")
	log.SetFlags(0)

	// parse arguments using getopt
	var dir, in, out string
	opts, optind, err := getopt.Getopts(os.Args, "vd:i:o:")
	if err != nil {


@@ 57,6 60,7 @@ func main() {
		usage()
		return
	}

	// replace args if needed
	if dir == "-" {
		scanner := bufio.NewScanner(os.Stdin)


@@ 76,15 80,19 @@ func main() {
			out = scanner.Text()
		}
	}

	// set dir to default XDG path if blank
	dir = getConfig(dir)

	// walk the directory to get an entries list
	entries, err := walk(dir)
	if err != nil {
		fmt.Printf("Failed getting entries: %q %v\n", dir, err)
		log.Fatalf("failed getting entries: %q %v\n", dir, err)
	}

	// filter selection by key:value pair
	entries = filter(in, entries)

	// print output selections
	for _, entry := range entries {
		// print specified key