Skip to content

Conversation

@cyliu0
Copy link
Contributor

@cyliu0 cyliu0 commented Dec 3, 2020

To achieve the same goal as aws s3 ls --recursive --summarize --human-readable.

$ aws s3 ls s3://tmp --recursive --summarize --human-readable
2020-11-02 15:48:28  146 Bytes tmp/metadata
2020-11-02 15:48:25   95 Bytes tmp/test-schema-create.sql
2020-11-02 15:48:26  490 Bytes tmp/test.t-schema.sql
2020-11-02 15:48:26   11.1 MiB tmp/test.t.0.sql
2020-11-02 11:27:25  484 Bytes tmp/test.t1-schema.sql
2020-11-02 11:27:26    8.8 MiB tmp/test.t1.0.sql
2020-11-02 11:27:25  182 Bytes tmp/test.test-schema.sql

Total Objects: 7
   Total Size: 19.9 MiB

$ ./mc ls s3/tmp --recursive --summarize
[2020-11-02 15:48:28 CST]   146B tmp/metadata
[2020-11-02 15:48:25 CST]    95B tmp/test-schema-create.sql
[2020-11-02 15:48:26 CST]   490B tmp/test.t-schema.sql
[2020-11-02 15:48:26 CST]  11MiB tmp/test.t.0.sql
[2020-11-02 11:27:25 CST]   484B tmp/test.t1-schema.sql
[2020-11-02 11:27:26 CST] 8.8MiB tmp/test.t1.0.sql
[2020-11-02 11:27:25 CST]   182B tmp/test.test-schema.sql
Total Objects: 7
   Total Size: 20MiB

@harshavardhana
Copy link
Member

harshavardhana commented Dec 7, 2020

I think I prefer the following style output

[2020-12-06 16:50:41 PST]     0B wego/
[2020-12-07 00:44:07 PST] 8.7KiB wego/2020-12-07/171607330645605.png
[2020-12-06 18:58:38 PST] 8.7KiB wego/2020-12-07/18311607309917728.png
[2020-12-06 16:50:42 PST] 105KiB wego/2020-12-07/31481607302239954.jpeg
[2020-12-07 00:44:34 PST] 8.7KiB wego/2020-12-07/33881607330673939.png
[2020-12-06 22:35:12 PST]  11KiB wego/2020-12-07/55721607322910849.docx
[2020-12-06 19:09:09 PST] 8.7KiB wego/2020-12-07/64931607310547415.png
[2020-12-06 19:09:28 PST] 8.7KiB wego/2020-12-07/66211607310567501.png
[2020-12-06 19:06:26 PST] 8.7KiB wego/2020-12-07/69091607310385503.png
[2020-12-06 22:39:54 PST] 3.7MiB wego/2020-12-07/71031607323193157.zip
[2020-12-06 16:50:44 PST]  12KiB wego/2020-12-07/71941607302243156.jpg
[2020-12-06 18:36:24 PST] 8.7KiB wego/2020-12-07/89751607308582600.png
[2020-12-06 21:51:56 PST] 7.7KiB wego/2020-12-07/test/test.png
[2020-12-06 22:41:41 PST] 7.7KiB wego/2020-12-07/test/test1.png
[2020-12-07 11:56:46 PST]     0B zfutkuzki/

Total Size: 2.7 GiB
Total Objects: 2850

With the following changes, AWS CLI output looks clumsy, we can make it look better.

git diff
diff --git a/cmd/ls-main.go b/cmd/ls-main.go
index 9686230d..df726b03 100644
--- a/cmd/ls-main.go
+++ b/cmd/ls-main.go
@@ -183,6 +183,7 @@ func mainList(cliCtx *cli.Context) error {
        console.SetColor("Dir", color.New(color.FgCyan, color.Bold))
        console.SetColor("Size", color.New(color.FgYellow))
        console.SetColor("Time", color.New(color.FgGreen))
+       console.SetColor("Summarize", color.New(color.Bold))
 
        // check 'ls' cliCtx arguments.
        args, isRecursive, isIncomplete, isSummary, timeRef, withOlderVersions := checkListSyntax(ctx, cliCtx)
diff --git a/cmd/ls.go b/cmd/ls.go
index 7899baa9..f1f99acd 100644
--- a/cmd/ls.go
+++ b/cmd/ls.go
@@ -179,8 +179,9 @@ type summaryMessage struct {
 
 // String colorized string message
 func (s summaryMessage) String() string {
-       message := console.Colorize("Total Objects", fmt.Sprintf("Total Objects: %d", s.TotalObjects)) + "\n" + console.Colorize("Total Size", fmt.Sprintf("%14s %s", "Total Size:", strings.Join(strings.Fields(humanize.IBytes(uint64(s.TotalSize))), "")))
-       return message
+       msg := console.Colorize("Summarize", fmt.Sprintf("\nTotal Size: %s", humanize.IBytes(uint64(s.TotalSize))))
+       msg += "\n" + console.Colorize("Summarize", fmt.Sprintf("Total Objects: %d", s.TotalObjects))
+       return msg
 }
 
 // JSON jsonified summary message
@@ -258,11 +259,10 @@ func doList(ctx context.Context, clnt Client, isRecursive, isIncomplete, isSumma
        printObjectVersions(clnt.GetURL(), perObjectVersions, withOlderVersions, isSummary)
 
        if isSummary {
-               sm := summaryMessage{
+               printMsg(summaryMessage{
                        TotalObjects: totalObjects,
                        TotalSize:    totalSize,
-               }
-               printMsg(sm)
+               })
        }
 
        return cErr

Thanks for the PR

@harshavardhana harshavardhana merged commit 74fc02e into minio:master Dec 9, 2020
@cyliu0 cyliu0 deleted the add-ls-summary branch December 10, 2020 02:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants