Example #1
0
func handleList(ctx *cli.Context, client *daemon.Client) error {
	path := "/"
	if ctx.NArg() > 0 {
		path = prefixSlash(ctx.Args().First())
	}

	depth := ctx.Int("depth")
	if ctx.Bool("recursive") {
		depth = -1
	}

	entries, err := client.List(path, depth)
	if err != nil {
		return ExitCode{
			UnknownError,
			fmt.Sprintf("ls: %v", err),
		}
	}

	for _, entry := range entries {
		modTime := time.Time{}
		if err := modTime.UnmarshalText(entry.ModTime); err != nil {
			log.Warningf("Could not parse mtime (%s): %v", entry.ModTime, err)
			continue
		}

		fmt.Printf(
			"%s\t%s\t%s\n",
			colors.Colorize(
				humanize.Bytes(uint64(entry.NodeSize)),
				colors.Green,
			),
			colors.Colorize(
				humanize.Time(modTime),
				colors.Cyan,
			),
			colors.Colorize(
				entry.Path,
				colors.Magenta,
			),
		)
	}

	return nil
}
Example #2
0
func handleTree(ctx *cli.Context, client *daemon.Client) error {
	path := "/"
	if ctx.NArg() > 0 {
		path = prefixSlash(ctx.Args().First())
	}

	depth := ctx.Int("depth")
	dirlist, err := client.List(path, depth)
	if err != nil {
		return ExitCode{
			UnknownError,
			fmt.Sprintf("ls: %v", err),
		}
	}

	if err := showTree(dirlist, depth); err != nil {
		return ExitCode{
			UnknownError,
			fmt.Sprintf("Printing tree failed: %v", err),
		}
	}

	return nil
}