func handlePkgs(t *depth.Tree, pkgs []string, outputJSON bool) error {
	for _, pkg := range pkgs {
		err := t.Resolve(pkg)
		if err != nil {
			fmt.Printf("'%v': FATAL: %v\n", pkg, err)
			return err
		}
		if outputJSON {
			writePkgJSON(os.Stdout, *t.Root)
			continue
		}
		writePkg(os.Stdout, *t.Root, 0, false)
	}
	return nil
}
handlePkgs takes a slice of package names, resolves a Tree on them,
and outputs each Tree to Stdout.
package main
import (
	"encoding/json"
	"flag"
	"fmt"
	"io"
	"os"
	"strings"
	"github.com/KyleBanks/depth"
)
const (
	outputPadding    = "  "
	outputPrefix     = "├ "
	outputPrefixLast = "└ "
)
var outputJSON bool
func main() {
	t, pkgs := parse(os.Args[1:])
	if err := handlePkgs(t, pkgs, outputJSON); err != nil {
		os.Exit(1)
	}
}
func parse(args []string) (*depth.Tree, []string) {
	f := flag.NewFlagSet(os.Args[0], flag.ExitOnError)
	var t depth.Tree
	f.BoolVar(&t.ResolveInternal, "internal", false, "If set, resolves dependencies of internal (stdlib) packages.")
	f.BoolVar(&t.ResolveTest, "test", false, "If set, resolves dependencies used for testing.")
	f.IntVar(&t.MaxDepth, "max", 0, "Sets the maximum depth of dependencies to resolve.")
	f.BoolVar(&outputJSON, "json", false, "If set, outputs the depencies in JSON format.")
	f.Parse(args)
	return &t, f.Args()
}