diff --git a/NOTICE b/NOTICE index a803f0be..e91b717d 100644 --- a/NOTICE +++ b/NOTICE @@ -1,4 +1,4 @@ -Mini Copy, (C) 2014,2015 Minio, Inc. +Mini Copy (C) 2014, 2015 Minio, Inc. This product includes software developed at Minio, Inc. (http://minio.io/). diff --git a/acl.go b/acl.go index 2de3fa1b..f0e54443 100644 --- a/acl.go +++ b/acl.go @@ -1,3 +1,19 @@ +/* + * Mini Copy (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. + * 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. + */ + package main // isValidBucketACL - is provided acl string supported diff --git a/aliases.go b/aliases.go index f52a2303..af3f5d3c 100644 --- a/aliases.go +++ b/aliases.go @@ -1,5 +1,5 @@ /* - * Mini Copy, (C) 2015 Minio, Inc. + * Mini Copy (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. diff --git a/aliases_test.go b/aliases_test.go index f03bc044..2df06bf2 100644 --- a/aliases_test.go +++ b/aliases_test.go @@ -1,5 +1,5 @@ /* - * Mini Copy, (C) 2014, 2015 Minio, Inc. + * Mini Copy (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. diff --git a/buildscripts/checkdeps.sh b/buildscripts/checkdeps.sh index 13e22842..414d6f20 100755 --- a/buildscripts/checkdeps.sh +++ b/buildscripts/checkdeps.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash # -# Mini Copy, (C) 2015 Minio, Inc. +# Mini Copy (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. diff --git a/buildscripts/git-commit-id.sh b/buildscripts/git-commit-id.sh old mode 100644 new mode 100755 index 8671f1d0..69638828 --- a/buildscripts/git-commit-id.sh +++ b/buildscripts/git-commit-id.sh @@ -1,4 +1,20 @@ #!/usr/bin/env bash +# +# Mini Copy (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. +# + CONST_FILE=build-constants.go diff --git a/cmd-common.go b/cmd-common.go index a8cfbf7a..f83423df 100644 --- a/cmd-common.go +++ b/cmd-common.go @@ -1,5 +1,5 @@ /* - * Mini Copy, (C) 2014, 2015 Minio, Inc. + * Mini Copy (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. diff --git a/cmd-common_test.go b/cmd-common_test.go index 2ddf1573..bd84ac62 100644 --- a/cmd-common_test.go +++ b/cmd-common_test.go @@ -1,5 +1,5 @@ /* - * Mini Copy, (C) 2014, 2015 Minio, Inc. + * Mini Copy (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. diff --git a/cmd-config.go b/cmd-config.go index 6212a569..fa3eba1b 100644 --- a/cmd-config.go +++ b/cmd-config.go @@ -1,5 +1,5 @@ /* - * Mini Copy, (C) 2014, 2015 Minio, Inc. + * Mini Copy (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. @@ -310,19 +310,19 @@ func doConfigCmd(ctx *cli.Context) { configPath, err := getMcConfigPath() if err != nil { log.Debug.Println(iodine.New(err, nil)) - console.Fatalln("mc: Unable to identify config file path") + console.Fatalln("Unable to determine config file path.") } err = saveConfig(ctx) if err != nil { switch iodine.ToError(err).(type) { case errConfigExists: log.Debug.Println(iodine.New(err, nil)) - console.Fatalln("mc: Configuration file " + configPath + " already exists") + console.Fatalln("Configuration file " + configPath + " already exists.") default: // unexpected error log.Debug.Println(iodine.New(err, nil)) - console.Fatalln("mc: Unable to generate config file", configPath) + console.Fatalln("Unable to generate config file", configPath, ".") } } - console.Infoln("mc: Configuration written to " + configPath + ". Please update your access credentials.") + console.Infoln("Configuration written to " + configPath + ". Please update your access credentials.") } diff --git a/cmd-config_test.go b/cmd-config_test.go index d34ba86e..a2794cea 100644 --- a/cmd-config_test.go +++ b/cmd-config_test.go @@ -1,5 +1,5 @@ /* - * Mini Copy, (C) 2014, 2015 Minio, Inc. + * Mini Copy (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. diff --git a/cmd-cp-recursive.go b/cmd-cp-recursive.go index a1f32a27..a7f81c63 100644 --- a/cmd-cp-recursive.go +++ b/cmd-cp-recursive.go @@ -1,5 +1,5 @@ /* - * Mini Copy, (C) 2015 Minio, Inc. + * Mini Copy (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. @@ -17,7 +17,6 @@ package main import ( - "fmt" "strings" "github.com/minio-io/mc/pkg/console" @@ -30,20 +29,22 @@ const ( ) // doCopyCmdRecursive - copy bucket to bucket -func doCopyCmdRecursive(manager clientManager, sourceURLConfigMap map[string]*hostConfig, targetURLConfigMap map[string]*hostConfig) (string, error) { +func doCopyCmdRecursive(manager clientManager, sourceURLConfigMap map[string]*hostConfig, targetURLConfigMap map[string]*hostConfig) error { for sourceURL, sourceConfig := range sourceURLConfigMap { // get source list clnt, err := manager.getNewClient(sourceURL, sourceConfig, false) if err != nil { - return fmt.Sprintf("instantiating a new client for URL [%s]", sourceURL), iodine.New(err, nil) + return iodine.New(err, map[string]string{"Source": sourceURL}) } + for itemCh := range clnt.List() { if itemCh.Err != nil { - return fmt.Sprintf("listing objects failed for URL [%s]", sourceURL), iodine.New(itemCh.Err, nil) + return iodine.New(err, map[string]string{"Source": sourceURL}) } if itemCh.Item.FileType.IsDir() { continue } + // populate source urls sourceURLs := make(map[string]*hostConfig) sourceObjectURL := itemCh.Item.Name @@ -54,13 +55,13 @@ func doCopyCmdRecursive(manager clientManager, sourceURLConfigMap map[string]*ho targetObjectURL := strings.TrimSuffix(targetURL, pathSeparator) + pathSeparator + itemCh.Item.Name targetURLs[targetObjectURL] = targetConfig } - humanReadable, err := doCopyCmd(manager, sourceURLs, targetURLs) + err := doCopyCmd(manager, sourceURLs, targetURLs) if err != nil { err := iodine.New(err, nil) log.Debug.Println(err) - console.Errorln(humanReadable) + console.Errorln("Failed to copy from %s to %s. Reason: [%s].\n", sourceURLs, targetURLs, iodine.ToError(err)) } } } - return "", nil + return nil } diff --git a/cmd-cp.go b/cmd-cp.go index 33251ed6..c8b4e7a6 100644 --- a/cmd-cp.go +++ b/cmd-cp.go @@ -1,5 +1,5 @@ /* - * Mini Copy, (C) 2014,2015 Minio, Inc. + * Mini Copy (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. @@ -17,7 +17,6 @@ package main import ( - "fmt" "io" "strings" @@ -36,7 +35,7 @@ func runCopyCmd(ctx *cli.Context) { config, err := getMcConfig() if err != nil { log.Debug.Println(iodine.New(err, nil)) - console.Fatalf("mc: loading config file failed with following reason: [%s]\n", iodine.ToError(err)) + console.Fatalf("Unable to read config file [%s]. Reason: [%s].\n", mustGetMcConfigPath(), iodine.ToError(err)) } // Convert arguments to URLs: expand alias, fix format... @@ -45,10 +44,10 @@ func runCopyCmd(ctx *cli.Context) { switch e := iodine.ToError(err).(type) { case errUnsupportedScheme: log.Debug.Println(iodine.New(err, nil)) - console.Fatalf("mc: reading URL [%s] failed with following reason: [%s]\n", e.url, e) + console.Fatalf("Unknown type of URL(s).\n") default: log.Debug.Println(iodine.New(err, nil)) - console.Fatalf("mc: reading URLs failed with following reason: [%s]\n", e) + console.Fatalf("Unable to parse arguments. Reason: [%s].\n", e) } } @@ -64,53 +63,48 @@ func runCopyCmd(ctx *cli.Context) { sourceConfig, err := getHostConfig(sourceURL) if err != nil { log.Debug.Println(iodine.New(err, nil)) - console.Fatalf("mc: reading host config for URL [%s] failed with following reason: [%s]\n", sourceURL, iodine.ToError(err)) + console.Fatalf("Unable to read host configuration for source [%s] from config file [%s]. Reason: [%s].\n", + sourceURL, mustGetMcConfigPath(), iodine.ToError(err)) } sourceURLConfigMap[sourceURL] = sourceConfig targetURLConfigMap, err := getHostConfigs(targetURLs) if err != nil { log.Debug.Println(iodine.New(err, nil)) - console.Fatalf("mc: reading host configs failed with following reason: [%s]\n", iodine.ToError(err)) + console.Fatalf("Unable to read host configuration for the following targets %s from config file [%s]. Reason: [%s].\n", + targetURLs, mustGetMcConfigPath(), iodine.ToError(err)) } // perform recursive if recursive { - errorMsg, err := doCopyCmdRecursive(mcClientManager{}, sourceURLConfigMap, targetURLConfigMap) + err := doCopyCmdRecursive(mcClientManager{}, sourceURLConfigMap, targetURLConfigMap) err = iodine.New(err, nil) if err != nil { - if errorMsg == "" { - errorMsg = "No error message present, please rerun with --debug and report a bug." - } log.Debug.Println(err) - console.Fatalf("mc: %s with following reason: [%s]\n", errorMsg, iodine.ToError(err)) + console.Fatalf("Failed to copy recursively. Reason: [%s].\n", iodine.ToError(err)) } return } - errorMsg, err := doCopyCmd(mcClientManager{}, sourceURLConfigMap, targetURLConfigMap) + err = doCopyCmd(mcClientManager{}, sourceURLConfigMap, targetURLConfigMap) err = iodine.New(err, nil) if err != nil { - if errorMsg == "" { - errorMsg = "No error message present, please rerun with --debug and report a bug." - } log.Debug.Println(err) - console.Fatalf("mc: %s with following reason: [%s]\n", errorMsg, iodine.ToError(err)) + console.Fatalf("Failed to copy from source [%s] to target %s. Reason: [%s].\n", sourceURL, targetURLs, iodine.ToError(err)) } } // doCopyCmd copies objects into and from a bucket or between buckets -func doCopyCmd(manager clientManager, sourceURLConfigMap map[string]*hostConfig, targetURLConfigMap map[string]*hostConfig) (string, error) { +func doCopyCmd(manager clientManager, sourceURLConfigMap map[string]*hostConfig, targetURLConfigMap map[string]*hostConfig) error { for sourceURL, sourceConfig := range sourceURLConfigMap { reader, length, hexMd5, err := manager.getSourceReader(sourceURL, sourceConfig) if err != nil { - msg := fmt.Sprintf("Reading from source URL: [%s] failed", sourceURL) - return msg, iodine.New(err, nil) + return iodine.New(err, map[string]string{"Source": sourceURL}) } defer reader.Close() writeClosers, err := getTargetWriters(manager, targetURLConfigMap, hexMd5, length) if err != nil { - return "Writing to target URL failed", iodine.New(err, nil) + return iodine.New(err, nil) } var writers []io.Writer @@ -142,16 +136,16 @@ func doCopyCmd(manager clientManager, sourceURLConfigMap map[string]*hostConfig, } // write copy errors if present if copyErr != nil { - return "Copying data from source to target(s) failed", iodine.New(copyErr, nil) + return iodine.New(copyErr, map[string]string{"Source": sourceURL}) } // write close errors if present after checking copyErr if err != nil { - return "Connections still active, one or more writes may of failed.", iodine.New(err, nil) + return iodine.New(err, map[string]string{"Source": sourceURL}) } if !globalQuietFlag { bar.Finish() - console.Infoln("Success!") + // console.Infoln("Success!") } } - return "", nil + return nil } diff --git a/cmd-ls.go b/cmd-ls.go index 8eb1e773..45f1aae2 100644 --- a/cmd-ls.go +++ b/cmd-ls.go @@ -1,5 +1,5 @@ /* - * Mini Copy, (C) 2014,2015 Minio, Inc. + * Mini Copy (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. @@ -17,9 +17,8 @@ package main import ( - "time" - "fmt" + "time" "github.com/dustin/go-humanize" "github.com/minio-io/cli" @@ -40,7 +39,7 @@ func printItem(date time.Time, v int64, name string) { fmt.Println(console.File("%s", name)) } -func doList(clnt client.Client, targetURL string) (string, error) { +func doList(clnt client.Client, targetURL string) error { var err error for itemCh := range clnt.List() { if itemCh.Err != nil { @@ -49,12 +48,11 @@ func doList(clnt client.Client, targetURL string) (string, error) { } printItem(itemCh.Item.Time, itemCh.Item.Size, itemCh.Item.Name) } + if err != nil { - err = iodine.New(err, nil) - msg := fmt.Sprintf("mc: listing objects for URL [%s] failed with following reason: [%s]\n", targetURL, iodine.ToError(err)) - return msg, err + return iodine.New(err, map[string]string{"Target": targetURL}) } - return "", nil + return nil } // runListCmd lists objects inside a bucket @@ -65,7 +63,7 @@ func runListCmd(ctx *cli.Context) { config, err := getMcConfig() if err != nil { log.Debug.Println(iodine.New(err, nil)) - console.Fatalf("mc: Error reading config file. Reason: %s\n", iodine.ToError(err)) + console.Fatalf("Unable to read config file [%s]. Reason: [%s].\n", mustGetMcConfigPath(), iodine.ToError(err)) } targetURLConfigMap := make(map[string]*hostConfig) for _, arg := range ctx.Args() { @@ -74,39 +72,33 @@ func runListCmd(ctx *cli.Context) { switch iodine.ToError(err).(type) { case errUnsupportedScheme: log.Debug.Println(iodine.New(err, nil)) - console.Fatalf("mc: Unknown type of URL [%s].\n", arg) + console.Fatalf("Unknown type of URL [%s].\n", arg) default: log.Debug.Println(iodine.New(err, nil)) - console.Fatalf("mc: Unknown type of URL [%s]. Reason: %s\n", arg, iodine.ToError(err)) + console.Fatalf("Unable to parse argument [%s]. Reason: [%s].\n", arg, iodine.ToError(err)) } } targetConfig, err := getHostConfig(targetURL) if err != nil { log.Debug.Println(iodine.New(err, nil)) - console.Fatalf("mc: Error reading config for URL [%s]. Reason: %s\n", targetURL, iodine.ToError(err)) + console.Fatalf("Unable to read host configuration for [%s] from config file [%s]. Reason: [%s].\n", targetURL, mustGetMcConfigPath(), iodine.ToError(err)) } targetURLConfigMap[targetURL] = targetConfig } for targetURL, targetConfig := range targetURLConfigMap { - errorMsg, err := doListCmd(mcClientManager{}, targetURL, targetConfig, globalDebugFlag) + err = doListCmd(mcClientManager{}, targetURL, targetConfig, globalDebugFlag) err = iodine.New(err, nil) if err != nil { - if errorMsg == "" { - errorMsg = "mc: List command failed. Please re-run with --debug and report this bug." - } log.Debug.Println(err) - console.Errorf("%s", errorMsg) + console.Fatalf("Failed to list [%s]. Reason: [%s].\n", targetURL, iodine.ToError(err)) } } } -func doListCmd(manager clientManager, targetURL string, targetConfig *hostConfig, debug bool) (string, error) { +func doListCmd(manager clientManager, targetURL string, targetConfig *hostConfig, debug bool) error { clnt, err := manager.getNewClient(targetURL, targetConfig, globalDebugFlag) if err != nil { - err := iodine.New(err, nil) - msg := fmt.Sprintf("mc: instantiating a new client for URL [%s] failed with following reason: [%s]\n", - targetURL, iodine.ToError(err)) - return msg, err + return iodine.New(err, map[string]string{"Target": targetURL}) } return doList(clnt, targetURL) } diff --git a/cmd-mb.go b/cmd-mb.go index dd04494f..0d10a119 100644 --- a/cmd-mb.go +++ b/cmd-mb.go @@ -1,5 +1,5 @@ /* - * Mini Copy, (C) 2014,2015 Minio, Inc. + * Mini Copy (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. @@ -35,7 +35,7 @@ func runMakeBucketCmd(ctx *cli.Context) { config, err := getMcConfig() if err != nil { log.Debug.Println(iodine.New(err, nil)) - console.Fatalln("mc: Unable to read config") + console.Fatalf("Unable to read config file [%s].\n", mustGetMcConfigPath()) } targetURLConfigMap := make(map[string]*hostConfig) targetURLs, err := getURLs(ctx.Args(), config.Aliases) @@ -43,23 +43,23 @@ func runMakeBucketCmd(ctx *cli.Context) { switch e := iodine.ToError(err).(type) { case errUnsupportedScheme: log.Debug.Println(iodine.New(err, nil)) - console.Fatalf("mc: reading URL [%s] failed with following reason: [%s]\n", e.url, e) + console.Fatalf("Unknown URL type [%s] passed. Reason: [%s].\n", e.url, e) default: log.Debug.Println(iodine.New(err, nil)) - console.Fatalf("mc: reading URLs failed with following reason: [%s]\n", e) + console.Fatalf("Error in parsing path or URL. Reason: [%s].\n", e) } } acl := bucketACL(ctx.Args().First()) if !acl.isValidBucketACL() { log.Debug.Println(iodine.New(errInvalidACL{acl: acl.String()}, nil)) - console.Fatalf("mc: Unsupported type of acl requested [%s], supported types are [private, public-read, public-read-write]\n", acl) + console.Fatalf("Access type [%s] is not supported. Valid types are [private, private, read-only].\n", acl) } targetURLs = targetURLs[1:] // 1 or more target URLs for _, targetURL := range targetURLs { targetConfig, err := getHostConfig(targetURL) if err != nil { log.Debug.Println(iodine.New(err, nil)) - console.Fatalf("mc: reading config URL [%s] failed with following reason: [%s]\n", targetURL, iodine.ToError(err)) + console.Fatalf("Unable to read configuration for host [%s]. Reason: [%s].\n", targetURL, iodine.ToError(err)) } targetURLConfigMap[targetURL] = targetConfig } @@ -68,7 +68,7 @@ func runMakeBucketCmd(ctx *cli.Context) { err = iodine.New(err, nil) if err != nil { if errorMsg == "" { - errorMsg = "No error message present, please rerun with --debug and report a bug." + errorMsg = "Empty error message. Please rerun this command with --debug and file a bug report." } log.Debug.Println(err) console.Errorf("%s", errorMsg) @@ -82,7 +82,7 @@ func doMakeBucketCmd(manager clientManager, targetURL, targetACL string, targetC clnt, err = manager.getNewClient(targetURL, targetConfig, debug) if err != nil { err := iodine.New(err, nil) - msg := fmt.Sprintf("mc: instantiating a new client for URL [%s] failed with following reason: [%s]\n", + msg := fmt.Sprintf("Unable to initialize client for [%s]. Reason: [%s].\n", targetURL, iodine.ToError(err)) return msg, err } @@ -102,7 +102,7 @@ func doMakeBucket(clnt client.Client, targetURL, targetACL string) (string, erro } if err != nil { err := iodine.New(err, nil) - msg := fmt.Sprintf("\nmc: Creating bucket failed for URL [%s] with following reason: [%s]\n", targetURL, iodine.ToError(err)) + msg := fmt.Sprintf("Failed to create bucket for URL [%s]. Reason: [%s].\n", targetURL, iodine.ToError(err)) return msg, err } return "", nil diff --git a/cmd-options.go b/cmd-options.go index b4ac1b60..e0cae961 100644 --- a/cmd-options.go +++ b/cmd-options.go @@ -1,5 +1,5 @@ /* - * Mini Copy, (C) 2014,2015 Minio, Inc. + * Mini Copy (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. diff --git a/cmd-update.go b/cmd-update.go index e6bab040..d3d2dcbf 100644 --- a/cmd-update.go +++ b/cmd-update.go @@ -1,5 +1,5 @@ /* - * Mini Copy, (C) 2015 Minio, Inc. + * Mini Copy (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. diff --git a/cmd_test.go b/cmd_test.go index 7f33ca62..1646b094 100644 --- a/cmd_test.go +++ b/cmd_test.go @@ -1,5 +1,5 @@ /* - * Mini Copy, (C) 2014, 2015 Minio, Inc. + * Mini Copy (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. @@ -80,8 +80,7 @@ func (s *CmdTestSuite) TestCopyToSingleTarget(c *C) { manager.On("getSourceReader", sourceURL, sourceConfig).Return(sourceReader, dataLength, hexMd5, nil).Once() manager.On("getTargetWriter", targetURL, targetConfig, hexMd5, dataLength).Return(targetWriter, nil).Once() - msg, err := doCopyCmd(manager, sourceURLConfigMap, targetURLConfigMap) - c.Assert(msg, Equals, "") + err = doCopyCmd(manager, sourceURLConfigMap, targetURLConfigMap) c.Assert(err, IsNil) wg.Wait() c.Assert(err, IsNil) @@ -165,8 +164,7 @@ func (s *CmdTestSuite) TestCopyRecursive(c *C) { manager.On("getSourceReader", "hello2", sourceConfig).Return(sourceReader2, dataLen2, etag2, nil).Once() manager.On("getTargetWriter", targetURL+"hello2", targetConfig, etag2, dataLen2).Return(writer2, nil).Once() - msg, err := doCopyCmdRecursive(manager, sourceURLConfigMap, targetURLConfigMap) - c.Assert(msg, Equals, "") + err = doCopyCmdRecursive(manager, sourceURLConfigMap, targetURLConfigMap) c.Assert(err, IsNil) wg.Wait() @@ -202,8 +200,7 @@ func (s *CmdTestSuite) TestCopyCmdFailures(c *C) { targetURLConfigMap[targetURL] = targetConfig manager.On("getSourceReader", sourceURL, sourceConfig).Return(nilReadCloser, int64(0), "", errors.New("Expected Error")).Once() - msg, err := doCopyCmd(manager, sourceURLConfigMap, targetURLConfigMap) - c.Assert(len(msg) > 0, Equals, true) + err = doCopyCmd(manager, sourceURLConfigMap, targetURLConfigMap) c.Assert(err, Not(IsNil)) manager.AssertExpectations(c) @@ -217,10 +214,9 @@ func (s *CmdTestSuite) TestCopyCmdFailures(c *C) { manager.On("getSourceReader", sourceURL, sourceConfig).Return(reader1, dataLen1, etag1, nil).Once() manager.On("getTargetWriter", targetURL, targetConfig, etag1, dataLen1).Return(nil, errors.New("Expected Error")).Once() - msg, err = doCopyCmd(manager, sourceURLConfigMap, targetURLConfigMap) + err = doCopyCmd(manager, sourceURLConfigMap, targetURLConfigMap) writer1.Close() wg.Wait() - c.Assert(len(msg) > 0, Equals, true) c.Assert(err, Not(IsNil)) // target write fails @@ -242,9 +238,8 @@ func (s *CmdTestSuite) TestCopyCmdFailures(c *C) { }() manager.On("getSourceReader", sourceURL, sourceConfig).Return(reader2, dataLen1, etag1, nil).Once() manager.On("getTargetWriter", targetURL, targetConfig, etag1, dataLen1).Return(writer3, nil).Once() - msg, err = doCopyCmd(manager, sourceURLConfigMap, targetURLConfigMap) + err = doCopyCmd(manager, sourceURLConfigMap, targetURLConfigMap) wg.Wait() - c.Assert(len(msg) > 0, Equals, true) c.Assert(err, Not(IsNil)) c.Assert(n3, Equals, int64(3)) @@ -259,9 +254,8 @@ func (s *CmdTestSuite) TestCopyCmdFailures(c *C) { failClose = &FailClose{} manager.On("getSourceReader", sourceURL, sourceConfig).Return(reader4, dataLen1, etag1, nil).Once() manager.On("getTargetWriter", targetURL, targetConfig, etag1, dataLen1).Return(failClose, nil).Once() - msg, err = doCopyCmd(manager, sourceURLConfigMap, targetURLConfigMap) + err = doCopyCmd(manager, sourceURLConfigMap, targetURLConfigMap) wg.Wait() - c.Assert(len(msg) > 0, Equals, true) c.Assert(err, Not(IsNil)) } @@ -310,8 +304,7 @@ func (s *CmdTestSuite) TestLsCmdWithBucket(c *C) { } }() cl1.On("List").Return(itemCh).Once() - msg, err := doListCmd(manager, sourceURL, sourceConfig, false) - c.Assert(msg, Equals, "") + err = doListCmd(manager, sourceURL, sourceConfig, false) c.Assert(err, IsNil) manager.AssertExpectations(c) @@ -343,6 +336,7 @@ func (s *CmdTestSuite) TestLsCmdWithFilePath(c *C) { sourceURLConfigMap[sourceURL] = sourceConfig manager.On("getNewClient", sourceURL, sourceConfig, false).Return(cl1, nil).Once() + itemCh := make(chan client.ItemOnChannel) go func() { defer close(itemCh) @@ -354,8 +348,7 @@ func (s *CmdTestSuite) TestLsCmdWithFilePath(c *C) { } }() cl1.On("List").Return(itemCh).Once() - msg, err := doListCmd(manager, sourceURL, sourceConfig, false) - c.Assert(msg, Equals, "") + err = doListCmd(manager, sourceURL, sourceConfig, false) c.Assert(err, IsNil) manager.AssertExpectations(c) @@ -392,8 +385,7 @@ func (s *CmdTestSuite) TestLsCmdListsBuckets(c *C) { } }() cl1.On("List").Return(itemCh).Once() - msg, err := doListCmd(manager, sourceURL, sourceConfig, false) - c.Assert(msg, Equals, "") + err = doListCmd(manager, sourceURL, sourceConfig, false) c.Assert(err, IsNil) manager.AssertExpectations(c) diff --git a/doc.go b/doc.go index 23453d86..8258429b 100644 --- a/doc.go +++ b/doc.go @@ -1,5 +1,5 @@ /* - * Mini Copy, (C) 2014,2015 Minio, Inc. + * Mini Copy (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. diff --git a/errors.go b/errors.go index 2e3f5bde..82fcd9e4 100644 --- a/errors.go +++ b/errors.go @@ -1,5 +1,5 @@ /* - * Mini Copy, (C) 2014,2015 Minio, Inc. + * Mini Copy (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. diff --git a/globals.go b/globals.go index 3032d375..31806f4b 100644 --- a/globals.go +++ b/globals.go @@ -1,5 +1,5 @@ /* - * Mini Copy, (C) 2015 Minio, Inc. + * Mini Copy (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. diff --git a/main.go b/main.go index 1b55eccc..386d2b05 100644 --- a/main.go +++ b/main.go @@ -1,5 +1,5 @@ /* - * Mini Copy, (C) 2014, 2015 Minio, Inc. + * Mini Copy (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. @@ -31,12 +31,12 @@ import ( "github.com/minio-io/minio/pkg/utils/log" ) +// Check for the environment early on and gracefuly report. func checkConfig() { - // Check for the environment early on and gracefuly report. _, err := user.Current() if err != nil { log.Debug.Println(iodine.New(err, nil)) - console.Fatalln("mc: Unable to obtain user's home directory") + console.Fatalln("Unable to determine user's home directory") } // If config doesn't exist, do not attempt to read it @@ -48,11 +48,11 @@ func checkConfig() { _, err = getMcConfig() if err != nil { log.Debug.Println(iodine.New(err, nil)) - console.Fatalf("mc: Unable to read config file: %s\n", mustGetMcConfigPath()) + console.Fatalf("Unable to read config file: %s\n", mustGetMcConfigPath()) } } -// Tries to get os/arch/platform specific information +// Get os/arch/platform specific information. // Returns a map of current os/arch/platform/memstats func getSystemData() map[string]string { host, err := os.Hostname() @@ -100,17 +100,17 @@ func main() { if console.IsValidTheme(themeName) { err := console.SetTheme(themeName) if err != nil { - console.Fatalf("mc: failed to set theme [%s] with following reason: [%s]\n", themeName, iodine.ToError(err)) + console.Fatalf("Failed to set theme [%s]. Reason: [%s].\n", themeName, iodine.ToError(err)) } } else { - console.Fatalf("mc: Theme [%s] is not supported. Please choose from this list: %s\n", themeName, console.GetThemeNames()) + console.Fatalf("Theme [%s] is not supported. Please choose from this list: %s.\n", themeName, console.GetThemeNames()) } checkConfig() return nil } app.After = func(ctx *cli.Context) error { if !isMcConfigExist() && ctx.Command.Name != "config" { - console.Fatalln("mc: error ``mc`` is not configured. Please run \"mc config generate\".") + console.Fatalln("\"mc\" is not configured. Please run \"mc config generate\".") } return nil } diff --git a/mock_clientManager_test.go b/mock_clientManager_test.go index 8fe8b54a..c74a49be 100644 --- a/mock_clientManager_test.go +++ b/mock_clientManager_test.go @@ -1,3 +1,19 @@ +/* + * Mini Copy (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. + * 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. + */ + package main import ( diff --git a/notifier.go b/notifier.go index 73bf4201..9e61c7aa 100644 --- a/notifier.go +++ b/notifier.go @@ -1,5 +1,5 @@ /* - * Mini Copy, (C) 2015 Minio, Inc. + * Mini Copy (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. diff --git a/pkg/client/auth.go b/pkg/client/auth.go index a44c883e..c5a9f05d 100644 --- a/pkg/client/auth.go +++ b/pkg/client/auth.go @@ -1,5 +1,5 @@ /* - * Mini Copy, (C) 2015 Minio, Inc. + * Mini Copy (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. diff --git a/pkg/client/client.go b/pkg/client/client.go index e77efdb2..60c2f551 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -1,5 +1,5 @@ /* - * Mini Copy, (C) 2015 Minio, Inc. + * Mini Copy (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. diff --git a/pkg/client/client_test.go b/pkg/client/client_test.go index 4271bdf4..e8f0cbcc 100644 --- a/pkg/client/client_test.go +++ b/pkg/client/client_test.go @@ -1,5 +1,5 @@ /* - * Mini Copy, (C) 2015 Minio, Inc. + * Mini Copy (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. diff --git a/pkg/client/errors.go b/pkg/client/errors.go index 16978197..3b898a11 100644 --- a/pkg/client/errors.go +++ b/pkg/client/errors.go @@ -1,5 +1,5 @@ /* - * Mini Copy, (C) 2015 Minio, Inc. + * Mini Copy (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. diff --git a/pkg/client/fs/fs_errors.go b/pkg/client/fs/fs_errors.go index d112b5cf..9484aae5 100644 --- a/pkg/client/fs/fs_errors.go +++ b/pkg/client/fs/fs_errors.go @@ -1,3 +1,19 @@ +/* + * Mini Copy (C) 2015 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this fs 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. + */ + package fs // GenericFileError - generic file error diff --git a/pkg/client/fs/fs_multi_unix.go b/pkg/client/fs/fs_multi_unix.go index 632b4a76..72bf450f 100644 --- a/pkg/client/fs/fs_multi_unix.go +++ b/pkg/client/fs/fs_multi_unix.go @@ -1,7 +1,7 @@ // +build darwin drangofly freebsd linux nacl netbsd openbsd solaris /* - * Mini Copy, (C) 2015 Minio, Inc. + * Mini Copy (C) 2015 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this fs except in compliance with the License. diff --git a/pkg/client/fs/fs_multi_windows.go b/pkg/client/fs/fs_multi_windows.go index 74b37bac..4438d5a5 100644 --- a/pkg/client/fs/fs_multi_windows.go +++ b/pkg/client/fs/fs_multi_windows.go @@ -1,5 +1,5 @@ /* - * Mini Copy, (C) 2015 Minio, Inc. + * Mini Copy (C) 2015 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this fs except in compliance with the License. diff --git a/pkg/client/fs/fs_put_unix.go b/pkg/client/fs/fs_put_unix.go index 245dad6c..85387803 100644 --- a/pkg/client/fs/fs_put_unix.go +++ b/pkg/client/fs/fs_put_unix.go @@ -1,7 +1,7 @@ // +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris /* - * Mini Copy, (C) 2015 Minio, Inc. + * Mini Copy (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. diff --git a/pkg/client/fs/fs_put_windows.go b/pkg/client/fs/fs_put_windows.go index cd185fb5..88130305 100644 --- a/pkg/client/fs/fs_put_windows.go +++ b/pkg/client/fs/fs_put_windows.go @@ -1,5 +1,5 @@ /* - * Mini Copy, (C) 2015 Minio, Inc. + * Mini Copy (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. diff --git a/pkg/client/fs/fs_test.go b/pkg/client/fs/fs_test.go index 672f5443..9b86c7df 100644 --- a/pkg/client/fs/fs_test.go +++ b/pkg/client/fs/fs_test.go @@ -1,5 +1,5 @@ /* - * Mini Copy, (C) 2015 Minio, Inc. + * Mini Copy (C) 2015 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this fs except in compliance with the License. diff --git a/pkg/client/fs/fs_unix.go b/pkg/client/fs/fs_unix.go index 4726ddde..8e2436dd 100644 --- a/pkg/client/fs/fs_unix.go +++ b/pkg/client/fs/fs_unix.go @@ -1,7 +1,7 @@ // +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris /* - * Mini Copy, (C) 2015 Minio, Inc. + * Mini Copy (C) 2015 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this fs except in compliance with the License. diff --git a/pkg/client/fs/fs_windows.go b/pkg/client/fs/fs_windows.go index 9557ecfa..a23a88df 100644 --- a/pkg/client/fs/fs_windows.go +++ b/pkg/client/fs/fs_windows.go @@ -1,5 +1,5 @@ /* - * Mini Copy, (C) 2015 Minio, Inc. + * Mini Copy (C) 2015 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this fs except in compliance with the License. diff --git a/pkg/client/s3/auth.go b/pkg/client/s3/auth.go index ff9210c6..07e87393 100644 --- a/pkg/client/s3/auth.go +++ b/pkg/client/s3/auth.go @@ -21,7 +21,7 @@ limitations under the License. // ---------------------------------------- // /* - * Mini Copy, (C) 2015 Minio, Inc. + * Mini Copy (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. diff --git a/pkg/client/s3/auth_test.go b/pkg/client/s3/auth_test.go index 94e0e812..1d7bca97 100644 --- a/pkg/client/s3/auth_test.go +++ b/pkg/client/s3/auth_test.go @@ -21,7 +21,7 @@ limitations under the License. // ---------------------------------------- // /* - * Mini Copy, (C) 2015 Minio, Inc. + * Mini Copy (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. diff --git a/pkg/client/s3/bucket.go b/pkg/client/s3/bucket.go index c75ce1e6..ed5a1c54 100644 --- a/pkg/client/s3/bucket.go +++ b/pkg/client/s3/bucket.go @@ -21,7 +21,7 @@ limitations under the License. // ---------------------------------------- // /* - * Mini Copy, (C) 2015 Minio, Inc. + * Mini Copy (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. diff --git a/pkg/client/s3/bucket_list.go b/pkg/client/s3/bucket_list.go index fd927553..9f52ea86 100644 --- a/pkg/client/s3/bucket_list.go +++ b/pkg/client/s3/bucket_list.go @@ -1,5 +1,5 @@ /* - * Mini Copy, (C) 2015 Minio, Inc. + * Mini Copy (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. diff --git a/pkg/client/s3/client.go b/pkg/client/s3/client.go index cd3bcef2..9599a4ec 100644 --- a/pkg/client/s3/client.go +++ b/pkg/client/s3/client.go @@ -21,7 +21,7 @@ limitations under the License. // ---------------------------------------- // /* - * Mini Copy, (C) 2015 Minio, Inc. + * Mini Copy (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. diff --git a/pkg/client/s3/client_test.go b/pkg/client/s3/client_test.go index 6738aa45..642de6d2 100644 --- a/pkg/client/s3/client_test.go +++ b/pkg/client/s3/client_test.go @@ -21,7 +21,7 @@ limitations under the License. // ---------------------------------------- // /* - * Mini Copy, (C) 2015 Minio, Inc. + * Mini Copy (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. diff --git a/pkg/client/s3/errors.go b/pkg/client/s3/errors.go index 719f079c..e15a0795 100644 --- a/pkg/client/s3/errors.go +++ b/pkg/client/s3/errors.go @@ -1,5 +1,5 @@ /* - * Mini Copy, (C) 2015 Minio, Inc. + * Mini Copy (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. diff --git a/pkg/client/s3/globals.go b/pkg/client/s3/globals.go index f13f833b..ff8ca241 100644 --- a/pkg/client/s3/globals.go +++ b/pkg/client/s3/globals.go @@ -1,5 +1,5 @@ /* - * Mini Copy, (C) 2015 Minio, Inc. + * Mini Copy (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. diff --git a/pkg/client/s3/httptrace.go b/pkg/client/s3/httptrace.go index 10c8d119..b003643b 100644 --- a/pkg/client/s3/httptrace.go +++ b/pkg/client/s3/httptrace.go @@ -1,5 +1,5 @@ /* - * Mini Copy, (C) 2015 Minio, Inc. + * Mini Copy (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. diff --git a/pkg/client/s3/object_get.go b/pkg/client/s3/object_get.go index c3e31672..9f16b878 100644 --- a/pkg/client/s3/object_get.go +++ b/pkg/client/s3/object_get.go @@ -21,7 +21,7 @@ limitations under the License. // ---------------------------------------- // /* - * Mini Copy, (C) 2015 Minio, Inc. + * Mini Copy (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. diff --git a/pkg/client/s3/object_multi.go b/pkg/client/s3/object_multi.go index 5ba6eb9f..842f526f 100644 --- a/pkg/client/s3/object_multi.go +++ b/pkg/client/s3/object_multi.go @@ -1,5 +1,5 @@ /* - * Mini Copy, (C) 2015 Minio, Inc. + * Mini Copy (C) 2015 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this fs except in compliance with the License. diff --git a/pkg/client/s3/object_put.go b/pkg/client/s3/object_put.go index 4b5d866f..c57956a5 100644 --- a/pkg/client/s3/object_put.go +++ b/pkg/client/s3/object_put.go @@ -1,5 +1,5 @@ /* - * Mini Copy, (C) 2015 Minio, Inc. + * Mini Copy (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. diff --git a/pkg/client/s3/s3verify.go b/pkg/client/s3/s3verify.go index 31b440c2..b7448443 100644 --- a/pkg/client/s3/s3verify.go +++ b/pkg/client/s3/s3verify.go @@ -1,5 +1,5 @@ /* - * Mini Copy, (C) 2015 Minio, Inc. + * Mini Copy (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. diff --git a/pkg/client/s3/trace.go b/pkg/client/s3/trace.go index 6af2add1..1d95522b 100644 --- a/pkg/client/s3/trace.go +++ b/pkg/client/s3/trace.go @@ -1,5 +1,5 @@ /* - * Mini Copy, (C) 2015 Minio, Inc. + * Mini Copy (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. diff --git a/pkg/client/url.go b/pkg/client/url.go index 01b43056..3065cfb3 100644 --- a/pkg/client/url.go +++ b/pkg/client/url.go @@ -1,3 +1,19 @@ +/* + * Mini Copy (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. + * 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. + */ + package client import "net/url" diff --git a/pkg/console/console.go b/pkg/console/console.go index 107322a3..108dd577 100644 --- a/pkg/console/console.go +++ b/pkg/console/console.go @@ -1,5 +1,5 @@ /* - * Mini Copy, (C) 2015 Minio, Inc. + * Mini Copy (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. @@ -22,6 +22,8 @@ import ( "runtime" "sync" + "path/filepath" + "github.com/fatih/color" "github.com/minio-io/minio/pkg/iodine" ) @@ -35,30 +37,36 @@ var ( // currTheme is current theme currThemeName = GetDefaultThemeName() - // Fatal prints a fatal message and exits - Fatal = func(a ...interface{}) { themesDB[currThemeName].Fatal.Print(a...); os.Exit(1) } - // Fatalln prints a fatal message with a new line and exits - Fatalln = func(a ...interface{}) { themesDB[currThemeName].Fatal.Println(a...); os.Exit(1) } - // Fatalf prints a fatal message with formatting and exits - Fatalf = func(f string, a ...interface{}) { themesDB[currThemeName].Fatal.Printf(f, a...); os.Exit(1) } + // Fatal prints a error message and exits + Fatal = func(a ...interface{}) { print(themesDB[currThemeName].Fatal, "", a...); os.Exit(1) } + // Fatalln prints a error message with a new line and exits + Fatalln = func(a ...interface{}) { println(themesDB[currThemeName].Fatal, "", a...); os.Exit(1) } + // Fatalf prints a error message with formatting and exits + Fatalf = func(f string, a ...interface{}) { + printf(themesDB[currThemeName].Fatal, "", f, a...) + os.Exit(1) + } + // Error prints a error message - Error = func(a ...interface{}) { themesDB[currThemeName].Error.Print(a...) } + Error = func(a ...interface{}) { print(themesDB[currThemeName].Error, "", a...) } // Errorln prints a error message with a new line - Errorln = func(a ...interface{}) { themesDB[currThemeName].Error.Println(a...) } + Errorln = func(a ...interface{}) { println(themesDB[currThemeName].Error, "", a...) } // Errorf prints a error message with formatting - Errorf = func(f string, a ...interface{}) { themesDB[currThemeName].Error.Printf(f, a...) } + Errorf = func(f string, a ...interface{}) { printf(themesDB[currThemeName].Error, "", f, a...) } + // Info prints a informational message - Info = func(a ...interface{}) { themesDB[currThemeName].Info.Print(a...) } + Info = func(a ...interface{}) { print(themesDB[currThemeName].Info, "", a...) } // Infoln prints a informational message with a new line - Infoln = func(a ...interface{}) { themesDB[currThemeName].Info.Println(a...) } + Infoln = func(a ...interface{}) { println(themesDB[currThemeName].Info, "", a...) } // Infof prints a informational message with formatting - Infof = func(f string, a ...interface{}) { themesDB[currThemeName].Info.Printf(f, a...) } + Infof = func(f string, a ...interface{}) { printf(themesDB[currThemeName].Info, "", f, a...) } + // Debug prints a debug message - Debug = func(a ...interface{}) { themesDB[currThemeName].Debug.Print(a...) } + Debug = func(a ...interface{}) { print(themesDB[currThemeName].Debug, "", a...) } // Debugln prints a debug message with a new line - Debugln = func(a ...interface{}) { themesDB[currThemeName].Debug.Println(a...) } + Debugln = func(a ...interface{}) { println(themesDB[currThemeName].Debug, "", a...) } // Debugf prints a debug message with formatting - Debugf = func(f string, a ...interface{}) { themesDB[currThemeName].Debug.Printf(f, a...) } + Debugf = func(f string, a ...interface{}) { printf(themesDB[currThemeName].Debug, "", f, a...) } // File - File("foo.txt") File = themesDB[currThemeName].File.SprintfFunc() @@ -82,13 +90,29 @@ type Theme struct { var ( // wrap around standard fmt functions - print = func(a ...interface{}) { fmt.Print(a...) } - println = func(a ...interface{}) { fmt.Println(a...) } - printf = func(f string, a ...interface{}) { fmt.Printf(f, a...) } + // print prints a message prefixed with message type and program name + print = func(c *color.Color, prefix string, a ...interface{}) { + mutex.Lock() + c.Printf(ProgramName()+": %s ", prefix) + c.Print(a...) + mutex.Unlock() + } - fatalPrint = func(a ...interface{}) { fmt.Print(a...); os.Exit(1) } - fatalPrintln = func(a ...interface{}) { fmt.Println(a...); os.Exit(1) } - fatalPrintf = func(f string, a ...interface{}) { fmt.Printf(f, a...); os.Exit(1) } + // println - same as print with a new line + println = func(c *color.Color, prefix string, a ...interface{}) { + mutex.Lock() + c.Printf(ProgramName()+": %s ", prefix) + c.Println(a...) + mutex.Unlock() + } + + // printf - same as print, but takes a format specifier + printf = func(c *color.Color, prefix string, f string, a ...interface{}) { + mutex.Lock() + c.Printf(ProgramName()+": %s ", prefix) + c.Printf(f, a...) + mutex.Unlock() + } ) // SetTheme sets a color theme @@ -98,6 +122,7 @@ func SetTheme(themeName string) error { } mutex.Lock() + currThemeName = themeName theme := themesDB[currThemeName] @@ -109,18 +134,26 @@ func SetTheme(themeName string) error { color.NoColor = false } - Fatal = func(a ...interface{}) { theme.Fatal.Print(a...); os.Exit(1) } - Fatalln = func(a ...interface{}) { theme.Fatal.Println(a...); os.Exit(1) } - Fatalf = func(f string, a ...interface{}) { theme.Fatal.Printf(f, a...); os.Exit(1) } - Error = func(a ...interface{}) { theme.Error.Print(a...) } - Errorln = func(a ...interface{}) { theme.Error.Println(a...) } - Errorf = func(f string, a ...interface{}) { theme.Error.Printf(f, a...) } - Info = func(a ...interface{}) { theme.Info.Print(a...) } - Infoln = func(a ...interface{}) { theme.Info.Println(a...) } - Infof = func(f string, a ...interface{}) { theme.Info.Printf(f, a...) } - Debug = func(a ...interface{}) { theme.Debug.Print(a...) } - Debugln = func(a ...interface{}) { theme.Debug.Println(a...) } - Debugf = func(f string, a ...interface{}) { theme.Debug.Printf(f, a...) } + // Error prints a error message + Error = func(a ...interface{}) { print(theme.Error, "", a...) } + // Errorln prints a error message with a new line + Errorln = func(a ...interface{}) { println(theme.Error, "", a...) } + // Errorf prints a error message with formatting + Errorf = func(f string, a ...interface{}) { printf(theme.Error, "", f, a...) } + + // Info prints a informational message + Info = func(a ...interface{}) { print(theme.Info, "", a...) } + // Infoln prints a informational message with a new line + Infoln = func(a ...interface{}) { println(theme.Info, "", a...) } + // Infof prints a informational message with formatting + Infof = func(f string, a ...interface{}) { printf(theme.Info, "", f, a...) } + + // Debug prints a debug message + Debug = func(a ...interface{}) { print(theme.Debug, "", a...) } + // Debugln prints a debug message with a new line + Debugln = func(a ...interface{}) { println(theme.Debug, "", a...) } + // Debugf prints a debug message with formatting + Debugf = func(f string, a ...interface{}) { printf(theme.Debug, "", f, a...) } File = theme.File.SprintfFunc() Size = theme.Size.SprintfFunc() @@ -146,7 +179,6 @@ func GetDefaultThemeName() string { // GetThemeNames returns currently supported list of themes func GetThemeNames() (themeNames []string) { - for themeName := range themesDB { themeNames = append(themeNames, themeName) } @@ -158,3 +190,9 @@ func IsValidTheme(themeName string) bool { _, ok := themesDB[themeName] return ok } + +// ProgramName - return the name of the executable program +func ProgramName() string { + _, progName := filepath.Split(os.Args[0]) + return progName +} diff --git a/pkg/console/console_test.go b/pkg/console/console_test.go index f85e7160..486849bd 100644 --- a/pkg/console/console_test.go +++ b/pkg/console/console_test.go @@ -1,5 +1,5 @@ /* - * Mini Copy, (C) 2015 Minio, Inc. + * Mini Copy (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. diff --git a/pkg/console/themes.go b/pkg/console/themes.go index 713c87f7..a34508af 100644 --- a/pkg/console/themes.go +++ b/pkg/console/themes.go @@ -1,5 +1,5 @@ /* - * Mini Copy, (C) 2015 Minio, Inc. + * Mini Copy (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. @@ -31,7 +31,7 @@ var MiniTheme = Theme{ }*/ var MiniTheme = Theme{ Debug: (color.New(color.FgWhite, color.Faint, color.Italic)), - Fatal: (color.New(color.FgRed, color.Italic)), + Fatal: (color.New(color.FgRed, color.Italic, color.Bold)), Error: (color.New(color.FgYellow, color.Italic)), Info: (color.New(color.FgGreen, color.Bold)), File: (color.New(color.FgWhite)), diff --git a/pkg/quick/quick.go b/pkg/quick/quick.go index d25b9f39..e08c301e 100644 --- a/pkg/quick/quick.go +++ b/pkg/quick/quick.go @@ -1,7 +1,7 @@ /* * Quick - Quick key value store for config files and persistent state files * - * Mini Copy, (C) 2015 Minio, Inc. + * Mini Copy (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. diff --git a/pkg/quick/quick_test.go b/pkg/quick/quick_test.go index 0753e9ef..b486d557 100644 --- a/pkg/quick/quick_test.go +++ b/pkg/quick/quick_test.go @@ -1,7 +1,7 @@ /* * Quick - Quick key value store for config files and persistent state files * - * Mini Copy, (C) 2015 Minio, Inc. + * Mini Copy (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. diff --git a/url.go b/url.go index 7c344c30..83458fce 100644 --- a/url.go +++ b/url.go @@ -1,5 +1,5 @@ /* - * Mini Copy, (C) 2015 Minio, Inc. + * Mini Copy (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.