Пример #1
0
func main() {
	if len(os.Args) == 2 && ishelp(os.Args[1]) {
		fmt.Println(usage)
		return
	}
	if len(flag.Args()) > 1 {
		die(usage)
	}
	var (
		root      = "."
		spy       = memfs.New()
		printroot = true
	)
	if len(flags.Args()) == 1 {
		root = flags.Args()[0]
	}
	if root == "." {
		root, _ = os.Getwd()
		printroot = false
	}
	root = filepath.Clean(root)
	(fsutil.Control{FS: fsutil.Tee(fs.FS{}, spy), Hidden: all}).Find(root, lvl)
	spy, err := spy.Cd(root)
	if err != nil {
		die(err) // TODO(rjeczalik): improve error message
	}
	if gowidth > 0 || varname != "" {
		if err = EncodeLiteral(spy, gowidth, varname, os.Stdout); err != nil {
			die(err)
		}
	} else {
		if err = gotree(root, printroot, spy, os.Stdout); err != nil {
			die(err)
		}
	}
}
Пример #2
0
func cp(lhs, rhs fs.Filesystem, all bool, out string) {
	fs := fsutil.Tee(lhs, fsutil.Rel(rhs, out))
	c := fsutil.Control{FS: fs, Hidden: all}
	c.Find(sep, 0)
}