Skip to content

Commit

Permalink
Fixing find help message and behavior (#2320)
Browse files Browse the repository at this point in the history
  • Loading branch information
harshavardhana authored Dec 2, 2017
1 parent 336e7f5 commit 65c582c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
30 changes: 14 additions & 16 deletions cmd/find-main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...),
Expand Down Expand Up @@ -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
`,
Expand Down
10 changes: 6 additions & 4 deletions cmd/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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})
Expand Down

0 comments on commit 65c582c

Please sign in to comment.