From 65c582cd5bb97539a5661e182b2cecb96a1b818f Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Fri, 1 Dec 2017 18:04:09 -0800 Subject: [PATCH] Fixing find help message and behavior (#2320) --- cmd/find-main.go | 30 ++++++++++++++---------------- cmd/find.go | 10 ++++++---- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/cmd/find-main.go b/cmd/find-main.go index 02e5703fce..45f4385e4a 100644 --- a/cmd/find-main.go +++ b/cmd/find-main.go @@ -83,7 +83,7 @@ var ( var findCmd = cli.Command{ Name: "find", - Usage: "Finds files which match the given set of parameters.", + Usage: "Search for files and objects.", Action: mainFind, Before: setGlobalsFromContext, Flags: append(findFlags, globalFlags...), @@ -123,37 +123,35 @@ FORMAT {url} --> Substitutes to a shareable URL of the path. EXAMPLES: - 01. Find all files named foo from all buckets. - $ {{.HelpName}} s3 --name "file" + 01. Find all "foo.jpg" in all buckets under "s3" account. + $ {{.HelpName}} s3 --name "foo.jpg" - 02. Find all text files from mybucket. + 02. Find all objects with ".txt" extension under "s3/mybucket". $ {{.HelpName}} s3/mybucket --name "*.txt" - 03. Print only the object names without the directory component under this bucket. - $ {{.HelpName}} s3/bucket --name "*" -print {base} + 03. Find only the object names without the directory component under "s3/mybucket". + $ {{.HelpName}} s3/mybucket --name "*" -print {base} - 04. Copy all jpeg files from AWS S3 "s3/photos" bucket to minio "play/photos" bucket. - $ {{.HelpName}} s3/photos --name "*.jpg" --exec "mc cp {} play/photos" - - 05. Find all jpeg images from any folder prefixed with "album". + 04. Find all images with ".jpg" extension under "s3/photos", prefixed with "album". $ {{.HelpName}} s3/photos --name "*.jpg" --path "*/album*/*" - 06. Find all files with extensions jpeg, png, and gif using regex. + 05. Find all images with ".jpg", ".png", and ".gif" extentions, using regex under "s3/photos". $ {{.HelpName}} s3/photos --regex "(?i)\.(jpg|png|gif)$" - 07. Find all jpeg images from "s3/bucket" and copy to minio "play/bucket" *continuously*. + 06. Find all images with ".jpg" extension under "s3/bucket" and copy to "play/bucket" *continuously*. $ {{.HelpName}} s3/bucket --name "*.jpg" --watch --exec "mc cp {} play/bucket" - 08. Generate self expiring urls (7 days), for all objects between 64 MB, and 1 GB in size. + 07. Find and generate public URLs valid for 7 days, for all objects between 64 MB, and 1 GB in size under "s3" account. $ {{.HelpName}} s3 --larger 64MB --smaller 1GB --print {url} - 09. Find all files under the s3 bucket which were created within a week. + 08. Find all objects created in the last week under "s3/bucket". $ {{.HelpName}} s3/bucket --newer 1w - 10. Find all files which were created more than 6 months ago ignoring files ending in jpg. + 09. Find all objects which were created more than 6 months ago, and exclude the ones with ".jpg" + extension under "s3". $ {{.HelpName}} s3 --older 6m --ignore "*.jpg" - 11. List all objects up to 3 levels subdirectory deep. + 10. List all objects up to 3 levels sub-directory deep under "s3/bucket". $ {{.HelpName}} s3/bucket --maxdepth 3 `, diff --git a/cmd/find.go b/cmd/find.go index 9053666474..62e23e9362 100644 --- a/cmd/find.go +++ b/cmd/find.go @@ -109,7 +109,7 @@ func execFind(command string) { if err := cmd.Run(); err != nil { console.Fatalln(err) } - console.Println(out.String()) + console.Print(out.String()) } // watchFind - enables listening on the input path, listens for all file/object @@ -218,11 +218,13 @@ func find(ctx *findContext, fileContent contentMessage) { if !matchFind(ctx, fileContent) { return } // For all matching content + // proceed to either exec, format the output string. - switch { - case ctx.execCmd != "": + if ctx.execCmd != "" { execFind(stringsReplace(ctx.execCmd, fileContent)) - case ctx.printFmt != "": + return + } + if ctx.printFmt != "" { fileContent.Key = stringsReplace(ctx.printFmt, fileContent) } printMsg(findMessage{fileContent})