diff --git a/cmd/ls-main.go b/cmd/ls-main.go index 7190270d..1c7a8736 100644 --- a/cmd/ls-main.go +++ b/cmd/ls-main.go @@ -53,6 +53,10 @@ var ( Name: "summarize", Usage: "display summary information (number of objects, total size)", }, + cli.StringFlag{ + Name: "storage-class, sc", + Usage: "filter to specified storage class", + }, } ) @@ -102,6 +106,9 @@ EXAMPLES: 9. List all objects on mybucket, summarize the number of objects and total size. {{.Prompt}} {{.HelpName}} --summarize s3/mybucket/ + + 10. List all objects on mybucket, for the GLACIER storage class + {{.Prompt}} {{.HelpName}} --storage-class 'GLACIER' s3/mybucket `, } @@ -147,7 +154,7 @@ func parseRewindFlag(rewind string) (timeRef time.Time) { } // checkListSyntax - validate all the passed arguments -func checkListSyntax(ctx context.Context, cliCtx *cli.Context) ([]string, bool, bool, bool, time.Time, bool) { +func checkListSyntax(ctx context.Context, cliCtx *cli.Context) ([]string, bool, bool, bool, time.Time, bool, string) { args := cliCtx.Args() if !cliCtx.Args().Present() { args = []string{"."} @@ -168,7 +175,9 @@ func checkListSyntax(ctx context.Context, cliCtx *cli.Context) ([]string, bool, timeRef = time.Now().UTC() } - return args, isRecursive, isIncomplete, isSummary, timeRef, withOlderVersions + storageClasss := cliCtx.String("storage-class") + + return args, isRecursive, isIncomplete, isSummary, timeRef, withOlderVersions, storageClasss } // mainList - is a handler for mc ls command @@ -186,9 +195,10 @@ func mainList(cliCtx *cli.Context) error { console.SetColor("Size", color.New(color.FgYellow)) console.SetColor("Time", color.New(color.FgGreen)) console.SetColor("Summarize", color.New(color.Bold)) + console.SetColor("SC", color.New(color.FgBlue)) // check 'ls' cliCtx arguments. - args, isRecursive, isIncomplete, isSummary, timeRef, withOlderVersions := checkListSyntax(ctx, cliCtx) + args, isRecursive, isIncomplete, isSummary, timeRef, withOlderVersions, storageClassFilter := checkListSyntax(ctx, cliCtx) var cErr error for _, targetURL := range args { @@ -203,7 +213,7 @@ func mainList(cliCtx *cli.Context) error { fatalIf(err.Trace(targetURL), "Unable to initialize target `"+targetURL+"`.") } } - if e := doList(ctx, clnt, isRecursive, isIncomplete, isSummary, timeRef, withOlderVersions); e != nil { + if e := doList(ctx, clnt, isRecursive, isIncomplete, isSummary, timeRef, withOlderVersions, storageClassFilter); e != nil { cErr = e } } diff --git a/cmd/ls.go b/cmd/ls.go index d3abec2d..a5b411fc 100644 --- a/cmd/ls.go +++ b/cmd/ls.go @@ -50,6 +50,7 @@ type contentMessage struct { VersionOrd int `json:"versionOrdinal,omitempty"` VersionIndex int `json:"versionIndex,omitempty"` IsDeleteMarker bool `json:"isDeleteMarker,omitempty"` + StorageClass string `json:"storageClass,omitempty"` } // String colorized string message. @@ -58,6 +59,10 @@ func (c contentMessage) String() string { message += console.Colorize("Size", fmt.Sprintf("%7s", strings.Join(strings.Fields(humanize.IBytes(uint64(c.Size))), ""))) fileDesc := "" + if c.StorageClass != "" { + message += " " + console.Colorize("SC", c.StorageClass) + } + if c.VersionID != "" { fileDesc += console.Colorize("VersionID", " "+c.VersionID) + console.Colorize("VersionOrd", fmt.Sprintf(" v%d", c.VersionOrd)) if c.IsDeleteMarker { @@ -131,6 +136,7 @@ func generateContentMessages(clntURL ClientURL, ctnts []*ClientContent, printAll }() contentMsg.Size = c.Size + contentMsg.StorageClass = c.StorageClass md5sum := strings.TrimPrefix(c.ETag, "\"") md5sum = strings.TrimSuffix(md5sum, "\"") contentMsg.ETag = md5sum @@ -195,7 +201,7 @@ func printObjectVersions(clntURL ClientURL, ctntVersions []*ClientContent, print } // doList - list all entities inside a folder. -func doList(ctx context.Context, clnt Client, isRecursive, isIncomplete, isSummary bool, timeRef time.Time, withOlderVersions bool) error { +func doList(ctx context.Context, clnt Client, isRecursive, isIncomplete, isSummary bool, timeRef time.Time, withOlderVersions bool, filter string) error { var ( lastPath string perObjectVersions []*ClientContent @@ -233,7 +239,7 @@ func doList(ctx context.Context, clnt Client, isRecursive, isIncomplete, isSumma continue } - if content.StorageClass == s3StorageClassGlacier { + if content.StorageClass != "" && filter != "" && filter != "*" && content.StorageClass != filter { continue } diff --git a/cmd/tree-main.go b/cmd/tree-main.go index ff7b5f42..70a31cad 100644 --- a/cmd/tree-main.go +++ b/cmd/tree-main.go @@ -284,7 +284,7 @@ func mainTree(cliCtx *cli.Context) error { } clnt, err := newClientFromAlias(targetAlias, targetURL) fatalIf(err.Trace(targetURL), "Unable to initialize target `"+targetURL+"`.") - if e := doList(ctx, clnt, true, false, false, timeRef, false); e != nil { + if e := doList(ctx, clnt, true, false, false, timeRef, false, "*"); e != nil { cErr = e } }