Merge pull request #256 from harshavardhana/pr_out_add_coloring_outside_of_iodine_moving_iodine_messages_to_log_debug

This commit is contained in:
Harshavardhana
2015-04-06 12:51:23 -07:00
6 changed files with 96 additions and 35 deletions
+24 -6
View File
@@ -16,6 +16,7 @@ import (
"github.com/minio-io/cli"
"github.com/minio-io/iodine"
"github.com/minio-io/minio/pkg/utils/log"
)
const (
@@ -50,6 +51,9 @@ var _config *mcConfig
func getMcConfigDir() string {
u, err := user.Current()
if err != nil {
if globalDebugFlag {
log.Debug.Println(iodine.New(err, nil))
}
msg := fmt.Sprintf("Unable to obtain user's home directory. \nError: %s", err)
fatal(msg)
}
@@ -79,7 +83,8 @@ func checkMcConfig(config *mcConfig) (err error) {
// check for version
switch {
case (config.Version != currentConfigVersion):
return iodine.New(fmt.Errorf("Unsupported version [%d]. Current operating version is [%d]", config.Version, currentConfigVersion), nil)
err := fmt.Errorf("Unsupported version [%d]. Current operating version is [%d]", config.Version, currentConfigVersion)
return iodine.New(err, nil)
case len(config.Hosts) > 1:
for host, hostCfg := range config.Hosts {
@@ -180,9 +185,18 @@ func getBashCompletion() {
f := getMcBashCompletionFilename()
fl, err := os.OpenFile(f, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
defer fl.Close()
if err != nil {
if globalDebugFlag {
log.Debug.Println(iodine.New(err, nil))
}
fatal(err)
}
_, err = fl.Write(b.Bytes())
if err != nil {
fatal(iodine.New(err, nil))
if globalDebugFlag {
log.Debug.Println(iodine.New(err, nil))
}
fatal(err)
}
msg := "\nConfiguration written to " + f
msg = msg + "\n\n$ source ${HOME}/.minio/mc/mc.bash_completion\n"
@@ -288,15 +302,19 @@ func doConfigCmd(ctx *cli.Context) {
default:
err := saveConfig(ctx)
if os.IsExist(err) {
if globalDebugFlag {
log.Debug.Println(iodine.New(err, nil))
}
msg := fmt.Sprintf("mc: Please rename your current configuration file [%s]\n", getMcConfigFilename())
warning(msg)
fatal(iodine.New(err, nil))
fatal(msg)
}
if err != nil {
if globalDebugFlag {
log.Debug.Println(iodine.New(err, nil))
}
msg := fmt.Sprintf("mc: Unable to generate config file [%s]. \nError: %v\n", getMcConfigFilename(), err)
warning(msg)
fatal(iodine.New(err, nil))
fatal(msg)
}
info("Configuration written to " + getMcConfigFilename() + "\n")
}
+12 -3
View File
@@ -26,6 +26,7 @@ import (
"github.com/cheggaaa/pb"
"github.com/minio-io/cli"
"github.com/minio-io/iodine"
"github.com/minio-io/minio/pkg/utils/log"
)
type message struct {
@@ -116,6 +117,9 @@ func multiCopy(targetURLs []string, sourceURL string) (err error) {
for msg := range doPutMultiTarget(targetURLs, md5Hex, sourceSize, targetReaders) {
if msg.err != nil {
if globalDebugFlag {
log.Debug.Println(msg.err)
}
fatal(msg.err)
}
info("Done")
@@ -131,7 +135,10 @@ func doCopyCmd(ctx *cli.Context) {
// Convert arguments to URLs: expand alias, fix format...
urlList, err := parseURLs(ctx)
if err != nil {
fatal(iodine.New(err, nil))
if globalDebugFlag {
log.Debug.Println(iodine.New(err, nil))
}
fatal(err)
return
}
sourceURL := urlList[0] // First arg is source
@@ -139,9 +146,11 @@ func doCopyCmd(ctx *cli.Context) {
err = multiCopy(targetURLs, sourceURL)
if err != nil {
fatal(iodine.New(err, nil))
if globalDebugFlag {
log.Debug.Println(iodine.New(err, nil))
}
fatal(err)
return
}
return
}
+20 -7
View File
@@ -61,31 +61,44 @@ func doListCmd(ctx *cli.Context) {
urlStr, err := parseURL(ctx.Args().First())
if err != nil {
fatal(iodine.New(err, nil))
if globalDebugFlag {
log.Debug.Println(iodine.New(err, nil))
}
fatal(err)
}
bucketName, objectName, err := url2Object(urlStr)
if err != nil {
fatal(iodine.New(err, nil))
if globalDebugFlag {
log.Debug.Println(iodine.New(err, nil))
}
fatal(err)
}
client, err := getNewClient(globalDebugFlag, urlStr)
if err != nil {
fatal(iodine.New(err, nil))
if globalDebugFlag {
log.Debug.Println(iodine.New(err, nil))
}
fatal(err)
}
if bucketName == "" { // List all buckets
buckets, err := client.ListBuckets()
if err != nil {
log.Debug.Println(iodine.New(err, nil))
fatal(err.Error())
if globalDebugFlag {
log.Debug.Println(iodine.New(err, nil))
}
fatal(err)
}
printBuckets(buckets)
} else {
items, err = client.ListObjects(bucketName, objectName)
if err != nil {
log.Debug.Println(iodine.New(err, nil))
fatal(err.Error())
if globalDebugFlag {
log.Debug.Println(iodine.New(err, nil))
}
fatal(err)
}
printObjects(items)
}
+20 -10
View File
@@ -27,30 +27,40 @@ import (
func doMakeBucketCmd(ctx *cli.Context) {
urlStr, err := parseURL(ctx.Args().First())
if err != nil {
log.Debug.Println(iodine.New(err, nil))
fatal(err.Error())
if globalDebugFlag {
log.Debug.Println(iodine.New(err, nil))
}
fatal(err)
}
bucket, err := url2Bucket(urlStr)
if err != nil {
log.Debug.Println(iodine.New(err, nil))
fatal(err.Error())
if globalDebugFlag {
log.Debug.Println(iodine.New(err, nil))
}
fatal(err)
}
clnt, err := getNewClient(globalDebugFlag, urlStr)
if err != nil {
log.Debug.Println(iodine.New(err, nil))
fatal(err.Error())
if globalDebugFlag {
log.Debug.Println(iodine.New(err, nil))
}
fatal(err)
}
if !s3.IsValidBucketName(bucket) {
log.Debug.Println(iodine.New(err, nil))
fatal(errInvalidbucket.Error())
if globalDebugFlag {
log.Debug.Println(iodine.New(err, nil))
}
fatal(errInvalidbucket)
}
err = clnt.PutBucket(bucket)
if err != nil {
log.Debug.Println(iodine.New(err, nil))
fatal(err.Error())
if globalDebugFlag {
log.Debug.Println(iodine.New(err, nil))
}
fatal(err)
}
}
+13 -3
View File
@@ -26,13 +26,17 @@ import (
"github.com/cheggaaa/pb"
"github.com/minio-io/cli"
"github.com/minio-io/iodine"
"github.com/minio-io/minio/pkg/utils/log"
)
func init() {
// Check for the environment early on and gracefuly report.
_, err := user.Current()
if err != nil {
msg := fmt.Sprintf("mc: Unable to obtain user's home directory %s\n", iodine.New(err, nil))
if globalDebugFlag {
log.Debug.Println(iodine.New(err, nil))
}
msg := fmt.Sprintf("mc: Unable to obtain user's home directory %s\n", err)
fatal(msg)
}
@@ -42,13 +46,19 @@ func init() {
return
}
if err != nil {
msg := fmt.Sprintf("Unable to read config %s\n", iodine.New(err, nil))
if globalDebugFlag {
log.Debug.Println(iodine.New(err, nil))
}
msg := fmt.Sprintf("Unable to read config %s\n", err)
fatal(msg)
}
err = checkMcConfig(config)
if err != nil {
msg := fmt.Sprintf("Error in config file: %s\n%s", getMcConfigFilename(), iodine.New(err, nil))
if globalDebugFlag {
log.Debug.Println(iodine.New(err, nil))
}
msg := fmt.Sprintf("Error in config file: %s\n%s", getMcConfigFilename(), err)
fatal(msg)
}
}
+7 -6
View File
@@ -22,6 +22,7 @@ import (
"net/url"
"github.com/minio-io/cli"
"github.com/minio-io/iodine"
)
// URLType defines supported storage protocols
@@ -151,7 +152,7 @@ func url2Object(urlStr string) (bucketName, objectName string, err error) {
// url2Bucket converts URL to bucket name
func url2Bucket(urlStr string) (bucketName string, err error) {
bucketName, _, err = url2Object(urlStr)
return bucketName, err
return bucketName, iodine.New(err, nil)
}
// parseURL extracts URL string from a single cmd-line argument
@@ -162,7 +163,7 @@ func parseURL(arg string) (urlStr string, err error) {
// Load config file
config, err := getMcConfig()
if err != nil {
return "", err
return "", iodine.New(err, nil)
}
urlStr = config.DefaultHost
}
@@ -170,11 +171,11 @@ func parseURL(arg string) (urlStr string, err error) {
// Check and expand Alias
urlStr, err = aliasExpand(urlStr)
if err != nil {
return "", err
return "", iodine.New(err, nil)
}
if !isValidURL(urlStr) {
return "", errUnsupportedScheme
return "", iodine.New(errUnsupportedScheme, nil)
}
// If it is a file URL, rewrite to file:///path/to form
@@ -189,9 +190,9 @@ func parseURLs(c *cli.Context) (urlStr []string, err error) {
for _, arg := range c.Args() {
u, err := parseURL(arg)
if err != nil {
return nil, err
return nil, iodine.New(err, nil)
}
urlStr = append(urlStr, u)
}
return urlStr, err
return urlStr, iodine.New(err, nil)
}