mirror of
https://github.com/minio/mc.git
synced 2025-11-13 12:22:45 +03:00
console enhancements, consistent error message and janitor duty
This commit is contained in:
2
NOTICE
2
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/).
|
||||
|
||||
16
acl.go
16
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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
16
buildscripts/git-commit-id.sh
Normal file → Executable file
16
buildscripts/git-commit-id.sh
Normal file → Executable file
@@ -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
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.")
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
44
cmd-cp.go
44
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
|
||||
}
|
||||
|
||||
36
cmd-ls.go
36
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)
|
||||
}
|
||||
|
||||
18
cmd-mb.go
18
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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
30
cmd_test.go
30
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)
|
||||
|
||||
2
doc.go
2
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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
16
main.go
16
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
|
||||
}
|
||||
|
||||
@@ -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 (
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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, "<FATAL>", a...); os.Exit(1) }
|
||||
// Fatalln prints a error message with a new line and exits
|
||||
Fatalln = func(a ...interface{}) { println(themesDB[currThemeName].Fatal, "<FATAL>", a...); os.Exit(1) }
|
||||
// Fatalf prints a error message with formatting and exits
|
||||
Fatalf = func(f string, a ...interface{}) {
|
||||
printf(themesDB[currThemeName].Fatal, "<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, "<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, "<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, "<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, "<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, "<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, "<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, "<ERROR>", a...) }
|
||||
// Errorln prints a error message with a new line
|
||||
Errorln = func(a ...interface{}) { println(theme.Error, "<ERROR>", a...) }
|
||||
// Errorf prints a error message with formatting
|
||||
Errorf = func(f string, a ...interface{}) { printf(theme.Error, "<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, "<DEBUG>", a...) }
|
||||
// Debugln prints a debug message with a new line
|
||||
Debugln = func(a ...interface{}) { println(theme.Debug, "<DEBUG>", a...) }
|
||||
// Debugf prints a debug message with formatting
|
||||
Debugf = func(f string, a ...interface{}) { printf(theme.Debug, "<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
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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)),
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user