Merge pull request #219 from abperiasamy/globals
move all global variables to globals
This commit is contained in:
+1
-1
@@ -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())
|
||||
|
||||
+3
-3
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
+2
-3
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
+27
@@ -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
|
||||
)
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -49,8 +49,3 @@ type Item struct {
|
||||
type Prefix struct {
|
||||
Prefix string
|
||||
}
|
||||
|
||||
// Maxkeys listed per ListObjects()
|
||||
const (
|
||||
Maxkeys = 1000
|
||||
)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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
|
||||
)
|
||||
Reference in New Issue
Block a user