diff --git a/ls-main.go b/ls-main.go index 03a88436..75a15a0d 100644 --- a/ls-main.go +++ b/ls-main.go @@ -22,7 +22,6 @@ import ( "github.com/fatih/color" "github.com/minio/cli" "github.com/minio/mc/pkg/console" - "github.com/minio/minio/pkg/probe" ) // list files and folders. @@ -105,27 +104,16 @@ func mainList(ctx *cli.Context) { "Time": color.New(color.FgGreen), }) - config := mustGetMcConfig() - showFolderNames := len(args) > 1 - - for _, arg := range args { - targetURL := getAliasURL(arg, config.Aliases) - - if !globalJSONFlag && showFolderNames { - console.Println(arg + ":") - } + targetURLs, err := args2URLs(args) + fatalIf(err.Trace(args...), "One or more unknown URL types passed.") + var lsPrefixMode = len(targetURLs) > 1 + for _, targetURL := range targetURLs { // if recursive strip off the "..." - err := doListCmd(stripRecursiveURL(targetURL), isURLRecursive(targetURL)) + clnt, err := target2Client(stripRecursiveURL(targetURL)) + fatalIf(err.Trace(targetURL), "Unable to initialize target ‘"+targetURL+"’.") + + err = doList(clnt, isURLRecursive(targetURL), lsPrefixMode) fatalIf(err.Trace(targetURL), "Unable to list target ‘"+targetURL+"’.") } } - -// doListCmd list files on target -func doListCmd(targetURL string, recursive bool) *probe.Error { - clnt, err := target2Client(targetURL) - if err != nil { - return err.Trace(targetURL) - } - return doList(clnt, recursive).Trace(targetURL) -} diff --git a/ls.go b/ls.go index dc98ee66..624479ab 100644 --- a/ls.go +++ b/ls.go @@ -103,8 +103,15 @@ func parseContent(c *client.Content) ContentMessage { } // doList - list all entities inside a folder. -func doList(clnt client.Client, recursive bool) *probe.Error { +func doList(clnt client.Client, recursive, lsPrefixMode bool) *probe.Error { var err *probe.Error + parentContent, err := clnt.Stat() + if err != nil { + return err.Trace(clnt.URL().String()) + } + if parentContent.Type.IsDir() && lsPrefixMode { + console.Println(console.Colorize("Dir", fmt.Sprintf("%s", clnt.URL().String()))) + } for contentCh := range clnt.List(recursive) { if contentCh.Err != nil { switch contentCh.Err.ToGoError().(type) {