diff --git a/cmd-common.go b/cmd-common.go index e38ed7c2..d83e35ea 100644 --- a/cmd-common.go +++ b/cmd-common.go @@ -176,7 +176,7 @@ func urlAliasExpander(arg string) (*url.URL, error) { // Parse subcommand options func parseArgs(c *cli.Context) (args *cmdArgs, err error) { args = new(cmdArgs) - args.quiet = c.GlobalBool("quiet") + args.quiet = globalQuietFlag switch len(c.Args()) { case 1: // only one URL urlString, err := aliasExpand(c.Args().First()) diff --git a/cmd-cp-recursive.go b/cmd-cp-recursive.go index bd432603..26b11871 100644 --- a/cmd-cp-recursive.go +++ b/cmd-cp-recursive.go @@ -112,7 +112,7 @@ func doRecursiveCP(c *cli.Context, args *cmdArgs) error { if err := sourceValidate(input); err != nil { return err } - s3c, err := getNewClient(c.GlobalBool("debug"), args.destination.url.String()) + s3c, err := getNewClient(globalDebugFlag, args.destination.url.String()) if err != nil { return err } @@ -130,11 +130,11 @@ func doRecursiveCP(c *cli.Context, args *cmdArgs) error { return err } case args.destination.bucket == "": - s3c, err := getNewClient(c.GlobalBool("debug"), args.source.url.String()) + s3c, err := getNewClient(globalDebugFlag, args.source.url.String()) if err != nil { return err } - items, _, err := s3c.ListObjects(args.source.bucket, "", "", "", client.Maxkeys) + items, _, err := s3c.ListObjects(args.source.bucket, "", "", "", globalMaxKeys) if err != nil { return err } diff --git a/cmd-cp.go b/cmd-cp.go index c91b0bef..2da1157b 100644 --- a/cmd-cp.go +++ b/cmd-cp.go @@ -88,7 +88,7 @@ func firstMode(c *cli.Context, args *cmdArgs) error { if args.destination.key == "" { args.destination.key = args.source.key } - s3c, err := getNewClient(c.GlobalBool("debug"), args.destination.url.String()) + s3c, err := getNewClient(globalDebugFlag, args.destination.url.String()) if err != nil { return err } @@ -116,7 +116,7 @@ func secondMode(c *cli.Context, args *cmdArgs) error { var err error var st os.FileInfo - s3c, err := getNewClient(c.GlobalBool("debug"), args.source.url.String()) + s3c, err := getNewClient(globalDebugFlag, args.source.url.String()) if err != nil { return err } @@ -201,7 +201,7 @@ func thirdMode(c *cli.Context, args *cmdArgs) error { var objectSize int64 var err error - s3cSource, err := getNewClient(c.GlobalBool("debug"), args.source.url.String()) + s3cSource, err := getNewClient(globalDebugFlag, args.source.url.String()) if err != nil { return err } @@ -216,7 +216,7 @@ func thirdMode(c *cli.Context, args *cmdArgs) error { } // Check if the object already exists - s3cDest, err := getNewClient(c.GlobalBool("debug"), args.destination.url.String()) + s3cDest, err := getNewClient(globalDebugFlag, args.destination.url.String()) if err != nil { return err } diff --git a/cmd-ls.go b/cmd-ls.go index 7819d198..7652c85a 100644 --- a/cmd-ls.go +++ b/cmd-ls.go @@ -84,7 +84,7 @@ func listObjectPrefix(s3c client.Client, bucketName, objectName string, maxkeys // doListCmd lists objects inside a bucket func doListCmd(c *cli.Context) { var items []*client.Item - // quiet := c.GlobalBool("quiet") + // quiet := globalQuietFlag urlStr, err := parseURL(c.Args().First()) if err != nil { @@ -96,7 +96,7 @@ func doListCmd(c *cli.Context) { fatal(err.Error()) } - s3c, err := getNewClient(c.GlobalBool("debug"), urlStr) + s3c, err := getNewClient(globalDebugFlag, urlStr) if err != nil { fatal(err.Error()) } @@ -109,13 +109,13 @@ func doListCmd(c *cli.Context) { } printBuckets(buckets) case objectName == "": // List objects in a bucket - items, _, err = s3c.ListObjects(bucketName, "", "", "", client.Maxkeys) + items, _, err = s3c.ListObjects(bucketName, "", "", "", globalMaxKeys) if err != nil { fatal(err.Error()) } printObjects(items) case objectName != "": // List objects matching the key prefix - listObjectPrefix(s3c, bucketName, objectName, client.Maxkeys) + listObjectPrefix(s3c, bucketName, objectName, globalMaxKeys) default: fatal(err.Error()) } diff --git a/cmd-mb.go b/cmd-mb.go index c0cc3716..bc09e04e 100644 --- a/cmd-mb.go +++ b/cmd-mb.go @@ -33,7 +33,7 @@ func doMakeBucketCmd(c *cli.Context) { fatal(err.Error()) } - s3c, err := getNewClient(c.GlobalBool("debug"), urlStr) + s3c, err := getNewClient(globalDebugFlag, urlStr) if err != nil { fatal(err.Error()) } diff --git a/colors.go b/colors.go index 03fb77b2..f12bb5d1 100644 --- a/colors.go +++ b/colors.go @@ -36,11 +36,15 @@ func warning(msg string) { } func info(msg string) { - green := ansi.ColorFunc("green") - fmt.Println(green(msg)) + if !globalQuietFlag { + green := ansi.ColorFunc("green") + fmt.Println(green(msg)) + } } func infoCallback(msg string) { - green := ansi.ColorFunc("green") - fmt.Print("\r" + green(msg)) + if !globalQuietFlag { + green := ansi.ColorFunc("green") + fmt.Print("\r" + green(msg)) + } } diff --git a/donut-cmd-ls.go b/donut-cmd-ls.go index 2f0d2163..465fde98 100644 --- a/donut-cmd-ls.go +++ b/donut-cmd-ls.go @@ -22,7 +22,6 @@ import ( "net/url" "github.com/minio-io/cli" - "github.com/minio-io/mc/pkg/client" "github.com/minio-io/mc/pkg/client/donut" ) @@ -64,12 +63,12 @@ func doDonutListCmd(c *cli.Context) { } printBuckets(buckets) case objectName == "": // List objects in a bucket - items, _, err := d.ListObjects(bucketName, "", "", "", client.Maxkeys) + items, _, err := d.ListObjects(bucketName, "", "", "", globalMaxKeys) if err != nil { fatal(err.Error()) } printObjects(items) case objectName != "": - listObjectPrefix(d, bucketName, objectName, client.Maxkeys) + listObjectPrefix(d, bucketName, objectName, globalMaxKeys) } } diff --git a/globals.go b/globals.go new file mode 100644 index 00000000..dc849102 --- /dev/null +++ b/globals.go @@ -0,0 +1,27 @@ +/* + * Minimalist Object Storage, (C) 2015 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// This package contains all the global variables and constants +package main + +var ( + globalQuietFlag = false // Quiet flag set via command line + globalDebugFlag = false // Debug flag set via command line +) + +const ( + globalMaxKeys = 1000 // Maximum number of keys to fetch per request +) diff --git a/main.go b/main.go index 609b1ab9..b3d028df 100644 --- a/main.go +++ b/main.go @@ -1,5 +1,5 @@ /* - * Minimalist Object Storage, (C) 2014,2015 Minio, Inc. + * Minimalist Object Storage, (C) 2014, 2015 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -55,5 +55,10 @@ func main() { app.Flags = flags app.Author = "Minio.io" app.EnableBashCompletion = true + app.Before = func(c *cli.Context) error { + globalQuietFlag = c.GlobalBool("quiet") + globalDebugFlag = c.GlobalBool("debug") + return nil + } app.Run(os.Args) } diff --git a/pkg/client/client.go b/pkg/client/client.go index a284e941..4f7915a3 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -49,8 +49,3 @@ type Item struct { type Prefix struct { Prefix string } - -// Maxkeys listed per ListObjects() -const ( - Maxkeys = 1000 -) diff --git a/pkg/client/donut/donut_test.go b/pkg/client/donut/donut_test.go index 3efbd944..1927e82a 100644 --- a/pkg/client/donut/donut_test.go +++ b/pkg/client/donut/donut_test.go @@ -232,7 +232,7 @@ func (s *MySuite) TestMultipleNewObjects(c *C) { c.Assert(readerBuffer2.Bytes(), DeepEquals, []byte("two")) // test list objects - listObjects, _, err := donut.ListObjects("foo", "", "", "", client.Maxkeys) + listObjects, _, err := donut.ListObjects("foo", "", "", "", globalMaxKeys) c.Assert(err, IsNil) receivedObjectNames := getObjectNames(listObjects) diff --git a/pkg/client/s3/bucket.go b/pkg/client/s3/bucket.go index 2ccbf48e..6b55a50d 100644 --- a/pkg/client/s3/bucket.go +++ b/pkg/client/s3/bucket.go @@ -182,8 +182,8 @@ func (c *s3Client) ListObjects(bucket string, startAt, prefix, delimiter string, marker := startAt for len(items) < maxKeys { fetchN := maxKeys - len(items) - if fetchN > client.Maxkeys { - fetchN = client.Maxkeys + if fetchN > globalMaxKeys { + fetchN = globalMaxKeys } var bres listBucketResults buffer.WriteString(fmt.Sprintf("%s?max-keys=%d", c.bucketURL(bucket), fetchN)) diff --git a/pkg/client/s3/globals.go b/pkg/client/s3/globals.go new file mode 100644 index 00000000..7b18d1c7 --- /dev/null +++ b/pkg/client/s3/globals.go @@ -0,0 +1,22 @@ +/* + * Minimalist Object Storage, (C) 2015 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// This package contains all s3 client specific global variables and constants +package s3 + +const ( + globalMaxKeys = 1000 // Maximum number of keys to fetch per request +)