From c2fcfe65127e86bbfa5c23fa4042e3ac42f3e050 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Thu, 18 Jul 2019 06:40:51 -0700 Subject: [PATCH] Make sure to error out if depth is -1 (#2828) Current code silently converts -1 to 0, which is not needed and we should fail instead. --- cmd/tree-main.go | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/cmd/tree-main.go b/cmd/tree-main.go index db2b9953..14cc3a9a 100644 --- a/cmd/tree-main.go +++ b/cmd/tree-main.go @@ -94,12 +94,12 @@ EXAMPLES: 3. List all buckets in "mybucket" on Amazon S3 cloud storage hosted on Microsoft Windows in a tree format. $ {{.HelpName}} s3\mybucket\ - + 4. List all buckets and objects in "mybucket" on Amazon S3 cloud storage in a tree format. - $ {{.HelpName}} -f myminio/mybucket/ - + $ {{.HelpName}} --files myminio/mybucket/ + 5. Set the depth of the tree for listing. - $ {{.HelpName}} -d 2 myminio/mybucket/ + $ {{.HelpName}} --depth 2 myminio/mybucket/ 6. List all the directories irrespective to the depth. $ {{.HelpName}} myminio/mybucket/ @@ -110,16 +110,11 @@ EXAMPLES: func checkTreeSyntax(ctx *cli.Context) { args := ctx.Args() - var depth = -1 if ctx.IsSet("depth") { - depth = ctx.Int("depth") - if depth == -1 { - depth = 0 + if ctx.Int("depth") <= 0 { + fatalIf(errInvalidArgument().Trace(args...), "depth should have a value greater than 0") } } - if depth != -1 && depth <= 0 { - fatalIf(errInvalidArgument().Trace(args...), "depth should have a value greater than 0") - } if (args.Present()) && len(args) == 0 { return