Merge pull request #689 from harshavardhana/pr_out_remove_console_to_depend_on_its_own_structures_instead_let_it_deal_with_interface_

This commit is contained in:
Harshavardhana
2015-05-24 13:02:07 -07:00
15 changed files with 185 additions and 161 deletions
+6 -6
View File
@@ -32,14 +32,14 @@ func runAccessCmd(ctx *cli.Context) {
cli.ShowCommandHelpAndExit(ctx, "access", 1) // last argument is exit code
}
if !isMcConfigExist() {
console.Fatalln(console.ErrorMessage{
console.Fatalln(ErrorMessage{
Message: "Please run \"mc config generate\"",
Error: iodine.New(errors.New("\"mc\" is not configured"), nil),
})
}
config, err := getMcConfig()
if err != nil {
console.Fatalln(console.ErrorMessage{
console.Fatalln(ErrorMessage{
Message: "loading config file failed",
Error: iodine.New(err, nil),
})
@@ -47,14 +47,14 @@ func runAccessCmd(ctx *cli.Context) {
targetURLConfigMap := make(map[string]*hostConfig)
targetURLs, err := getExpandedURLs(ctx.Args(), config.Aliases)
if err != nil {
console.Fatalln(console.ErrorMessage{
console.Fatalln(ErrorMessage{
Message: "Unknown type of URL ",
Error: iodine.New(err, nil),
})
}
acl := bucketACL(ctx.Args().First())
if !acl.isValidBucketACL() {
console.Fatalln(console.ErrorMessage{
console.Fatalln(ErrorMessage{
Message: "Valid types are [private, public, readonly].",
Error: iodine.New(errors.New("Invalid ACL Type ‘"+acl.String()+"’"), nil),
})
@@ -63,7 +63,7 @@ func runAccessCmd(ctx *cli.Context) {
for _, targetURL := range targetURLs {
targetConfig, err := getHostConfig(targetURL)
if err != nil {
console.Fatalln(console.ErrorMessage{
console.Fatalln(ErrorMessage{
Message: "Unable to read configuration for host " + "‘" + targetURL + "’",
Error: iodine.New(err, nil),
})
@@ -73,7 +73,7 @@ func runAccessCmd(ctx *cli.Context) {
for targetURL, targetConfig := range targetURLConfigMap {
errorMsg, err := doUpdateAccessCmd(targetURL, acl.String(), targetConfig)
if err != nil {
console.Errorln(console.ErrorMessage{
console.Errorln(ErrorMessage{
Message: errorMsg,
Error: iodine.New(err, nil),
})
+5 -5
View File
@@ -32,14 +32,14 @@ func runCatCmd(ctx *cli.Context) {
cli.ShowCommandHelpAndExit(ctx, "cat", 1) // last argument is exit code
}
if !isMcConfigExist() {
console.Fatalln(console.ErrorMessage{
console.Fatalln(ErrorMessage{
Message: "Please run \"mc config generate\"",
Error: iodine.New(errors.New("\"mc\" is not configured"), nil),
})
}
config, err := getMcConfig()
if err != nil {
console.Fatalln(console.ErrorMessage{
console.Fatalln(ErrorMessage{
Message: fmt.Sprintf("Unable to read config file ‘%s’", mustGetMcConfigPath()),
Error: iodine.New(err, nil),
})
@@ -48,7 +48,7 @@ func runCatCmd(ctx *cli.Context) {
// Convert arguments to URLs: expand alias, fix format...
urls, err := getExpandedURLs(ctx.Args(), config.Aliases)
if err != nil {
console.Fatalln(console.ErrorMessage{
console.Fatalln(ErrorMessage{
Message: fmt.Sprintf("Unknown type of URL ‘%s’", urls),
Error: iodine.New(err, nil),
})
@@ -57,14 +57,14 @@ func runCatCmd(ctx *cli.Context) {
sourceURLs := urls
sourceURLConfigMap, err := getHostConfigs(sourceURLs)
if err != nil {
console.Fatalln(console.ErrorMessage{
console.Fatalln(ErrorMessage{
Message: fmt.Sprintf("Unable to read host configuration for ‘%s’ from config file ‘%s’", sourceURLs, mustGetMcConfigPath()),
Error: iodine.New(err, nil),
})
}
humanReadable, err := doCatCmd(sourceURLConfigMap)
if err != nil {
console.Fatalln(console.ErrorMessage{
console.Fatalln(ErrorMessage{
Message: humanReadable,
Error: iodine.New(err, nil),
})
+3 -3
View File
@@ -34,19 +34,19 @@ func runConfigCmd(ctx *cli.Context) {
arg := ctx.Args().First()
tailArgs := ctx.Args().Tail()
if len(tailArgs) > 2 {
console.Fatalln(console.ErrorMessage{
console.Fatalln(ErrorMessage{
Message: "Incorrect number of arguments, please use \"mc config help\"",
Error: iodine.New(errInvalidArgument{}, nil),
})
}
msg, err := doConfig(arg, tailArgs)
if err != nil {
console.Fatalln(console.ErrorMessage{
console.Fatalln(ErrorMessage{
Message: msg,
Error: err,
})
}
console.Infoln(console.Message(msg))
console.Infoln(msg)
}
// saveConfig writes configuration data in json format to config file.
+4 -4
View File
@@ -35,7 +35,7 @@ func doCopy(sourceURL string, sourceConfig *hostConfig, targetURL string, target
}
switch globalQuietFlag {
case true:
console.Infoln(console.Message(fmt.Sprintf("‘%s’ -> ‘%s’", sourceURL, targetURL)))
console.Infoln(fmt.Sprintf("‘%s’ -> ‘%s’", sourceURL, targetURL))
default:
// set up progress
reader = bar.NewProxyReader(reader)
@@ -121,7 +121,7 @@ func runCopyCmd(ctx *cli.Context) {
}
if !isMcConfigExist() {
console.Fatalln(console.ErrorMessage{
console.Fatalln(ErrorMessage{
Message: "Please run \"mc config generate\"",
Error: iodine.New(errors.New("\"mc\" is not configured"), nil),
})
@@ -130,7 +130,7 @@ func runCopyCmd(ctx *cli.Context) {
// extract URLs.
URLs, err := args2URLs(ctx.Args())
if err != nil {
console.Fatalln(console.ErrorMessage{
console.Fatalln(ErrorMessage{
Message: fmt.Sprintf("Unknown URL types: ‘%s’", URLs),
Error: iodine.New(err, nil),
})
@@ -148,7 +148,7 @@ func runCopyCmd(ctx *cli.Context) {
}
for err := range doCopyCmd(sourceURLs, targetURL, bar) {
if err != nil {
console.Errorln(console.ErrorMessage{
console.Errorln(ErrorMessage{
Message: "Failed with",
Error: iodine.New(err, nil),
})
+10 -10
View File
@@ -31,14 +31,14 @@ func runDiffCmd(ctx *cli.Context) {
cli.ShowCommandHelpAndExit(ctx, "diff", 1) // last argument is exit code
}
if !isMcConfigExist() {
console.Fatalln(console.ErrorMessage{
console.Fatalln(ErrorMessage{
Message: "Please run \"mc config generate\"",
Error: iodine.New(errors.New("\"mc\" is not configured"), nil),
})
}
config, err := getMcConfig()
if err != nil {
console.Fatalln(console.ErrorMessage{
console.Fatalln(ErrorMessage{
Message: fmt.Sprintf("Unable to read config file ‘%s’", mustGetMcConfigPath()),
Error: err,
})
@@ -51,12 +51,12 @@ func runDiffCmd(ctx *cli.Context) {
if err != nil {
switch iodine.ToError(err).(type) {
case errUnsupportedScheme:
console.Fatalln(console.ErrorMessage{
console.Fatalln(ErrorMessage{
Message: fmt.Sprintf("Unknown type of URL ‘%s’", firstURL),
Error: err,
})
default:
console.Fatalln(console.ErrorMessage{
console.Fatalln(ErrorMessage{
Message: fmt.Sprintf("Unable to parse argument ‘%s’", firstURL),
Error: err,
})
@@ -65,7 +65,7 @@ func runDiffCmd(ctx *cli.Context) {
_, err = getHostConfig(firstURL)
if err != nil {
console.Fatalln(console.ErrorMessage{
console.Fatalln(ErrorMessage{
Message: fmt.Sprintf("Unable to read host configuration for ‘%s’ from config file ‘%s’", firstURL, mustGetMcConfigPath()),
Error: err,
})
@@ -73,7 +73,7 @@ func runDiffCmd(ctx *cli.Context) {
_, err = getHostConfig(secondURL)
if err != nil {
console.Fatalln(console.ErrorMessage{
console.Fatalln(ErrorMessage{
Message: fmt.Sprintf("Unable to read host configuration for ‘%s’ from config file ‘%s’", secondURL, mustGetMcConfigPath()),
Error: err,
})
@@ -83,12 +83,12 @@ func runDiffCmd(ctx *cli.Context) {
if err != nil {
switch iodine.ToError(err).(type) {
case errUnsupportedScheme:
console.Fatalln(console.ErrorMessage{
console.Fatalln(ErrorMessage{
Message: fmt.Sprintf("Unknown type of URL ‘%s’", secondURL),
Error: err,
})
default:
console.Fatalln(console.ErrorMessage{
console.Fatalln(ErrorMessage{
Message: fmt.Sprintf("Unable to parse argument ‘%s’", secondURL),
Error: err,
})
@@ -98,12 +98,12 @@ func runDiffCmd(ctx *cli.Context) {
newFirstURL := stripRecursiveURL(firstURL)
for diff := range doDiffCmd(newFirstURL, secondURL, isURLRecursive(firstURL)) {
if diff.err != nil {
console.Fatalln(console.ErrorMessage{
console.Fatalln(ErrorMessage{
Message: diff.message,
Error: diff.err,
})
}
console.Infoln(console.Message(diff.message))
console.Infoln(diff.message)
}
}
+6 -6
View File
@@ -31,14 +31,14 @@ func runListCmd(ctx *cli.Context) {
cli.ShowCommandHelpAndExit(ctx, "ls", 1) // last argument is exit code
}
if !isMcConfigExist() {
console.Fatalln(console.ErrorMessage{
console.Fatalln(ErrorMessage{
Message: "Please run \"mc config generate\"",
Error: iodine.New(errors.New("\"mc\" is not configured"), nil),
})
}
config, err := getMcConfig()
if err != nil {
console.Fatalln(console.ErrorMessage{
console.Fatalln(ErrorMessage{
Message: fmt.Sprintf("Unable to read config file ‘%s’", mustGetMcConfigPath()),
Error: iodine.New(err, nil),
})
@@ -49,12 +49,12 @@ func runListCmd(ctx *cli.Context) {
if err != nil {
switch e := iodine.ToError(err).(type) {
case errUnsupportedScheme:
console.Fatalln(console.ErrorMessage{
console.Fatalln(ErrorMessage{
Message: fmt.Sprintf("Unknown type of URL ‘%s’", e.url),
Error: iodine.New(e, nil),
})
default:
console.Fatalln(console.ErrorMessage{
console.Fatalln(ErrorMessage{
Message: fmt.Sprintf("Unable to parse argument ‘%s’", arg),
Error: iodine.New(err, nil),
})
@@ -62,7 +62,7 @@ func runListCmd(ctx *cli.Context) {
}
targetConfig, err := getHostConfig(targetURL)
if err != nil {
console.Fatalln(console.ErrorMessage{
console.Fatalln(ErrorMessage{
Message: fmt.Sprintf("Unable to read host configuration for ‘%s’ from config file ‘%s’", targetURL, mustGetMcConfigPath()),
Error: iodine.New(err, nil),
})
@@ -74,7 +74,7 @@ func runListCmd(ctx *cli.Context) {
newTargetURL := stripRecursiveURL(targetURL)
err = doListCmd(newTargetURL, targetConfig, isURLRecursive(targetURL))
if err != nil {
console.Fatalln(console.ErrorMessage{
console.Fatalln(ErrorMessage{
Message: fmt.Sprintf("Failed to list ‘%s’", targetURL),
Error: iodine.New(err, nil),
})
+6 -6
View File
@@ -33,14 +33,14 @@ func runMakeBucketCmd(ctx *cli.Context) {
cli.ShowCommandHelpAndExit(ctx, "mb", 1) // last argument is exit code
}
if !isMcConfigExist() {
console.Fatalln(console.ErrorMessage{
console.Fatalln(ErrorMessage{
Message: "Please run \"mc config generate\"",
Error: errors.New("\"mc\" is not configured"),
})
}
config, err := getMcConfig()
if err != nil {
console.Fatalln(console.ErrorMessage{
console.Fatalln(ErrorMessage{
Message: "Unable to read config file ‘" + mustGetMcConfigPath() + "’",
Error: err,
})
@@ -51,12 +51,12 @@ func runMakeBucketCmd(ctx *cli.Context) {
if err != nil {
switch e := iodine.ToError(err).(type) {
case errUnsupportedScheme:
console.Fatalln(console.ErrorMessage{
console.Fatalln(ErrorMessage{
Message: fmt.Sprintf("Unknown type of URL ‘%s’", e.url),
Error: e,
})
default:
console.Fatalln(console.ErrorMessage{
console.Fatalln(ErrorMessage{
Message: fmt.Sprintf("Unable to parse argument ‘%s’", arg),
Error: err,
})
@@ -64,7 +64,7 @@ func runMakeBucketCmd(ctx *cli.Context) {
}
targetConfig, err := getHostConfig(targetURL)
if err != nil {
console.Fatalln(console.ErrorMessage{
console.Fatalln(ErrorMessage{
Message: fmt.Sprintf("Unable to read host configuration for ‘%s’ from config file ‘%s’", targetURL, mustGetMcConfigPath()),
Error: err,
})
@@ -74,7 +74,7 @@ func runMakeBucketCmd(ctx *cli.Context) {
for targetURL, targetConfig := range targetURLConfigMap {
errorMsg, err := doMakeBucketCmd(targetURL, targetConfig)
if err != nil {
console.Errorln(console.ErrorMessage{
console.Errorln(ErrorMessage{
Message: errorMsg,
Error: err,
})
+6 -6
View File
@@ -33,7 +33,7 @@ func runSyncCmd(ctx *cli.Context) {
}
if !isMcConfigExist() {
console.Fatalln(console.ErrorMessage{
console.Fatalln(ErrorMessage{
Message: "Please run \"mc config generate\"",
Error: iodine.New(errors.New("\"mc\" is not configured"), nil),
})
@@ -41,7 +41,7 @@ func runSyncCmd(ctx *cli.Context) {
URLs, err := args2URLs(ctx.Args())
if err != nil {
console.Fatalln(console.ErrorMessage{
console.Fatalln(ErrorMessage{
Message: fmt.Sprintf("Unknown URL types found: ‘%s’", URLs),
Error: iodine.New(err, nil),
})
@@ -76,7 +76,7 @@ func runSyncCmd(ctx *cli.Context) {
for syncURLs := range prepareSyncURLs(sourceURL, targetURLs) {
if syncURLs.Error != nil {
console.Errorln(console.ErrorMessage{
console.Errorln(ErrorMessage{
Message: "Failed with",
Error: iodine.New(syncURLs.Error, nil),
})
@@ -88,7 +88,7 @@ func runSyncCmd(ctx *cli.Context) {
defer wg.Done()
srcConfig, err := getHostConfig(syncURLs.SourceContent.Name)
if err != nil {
console.Fatalln(console.ErrorMessage{
console.Fatalln(ErrorMessage{
Message: "Failed with",
Error: iodine.New(err, nil),
})
@@ -96,14 +96,14 @@ func runSyncCmd(ctx *cli.Context) {
}
tgtConfig, err := getHostConfig(syncURLs.TargetContent.Name)
if err != nil {
console.Fatalln(console.ErrorMessage{
console.Fatalln(ErrorMessage{
Message: "Failed with",
Error: iodine.New(err, nil),
})
return
}
if err := doCopy(syncURLs.SourceContent.Name, srcConfig, syncURLs.TargetContent.Name, tgtConfig, bar); err != nil {
console.Errorln(console.ErrorMessage{
console.Errorln(ErrorMessage{
Message: "Failed with",
Error: iodine.New(err, nil),
})
+5 -5
View File
@@ -48,7 +48,7 @@ func doUpdateCheck(config *hostConfig) (string, error) {
printUpdateNotify("new", "old")
return "", nil
}
return "You have latest build", nil
return "You are already running the most recent version of ‘mc’", nil
}
@@ -58,24 +58,24 @@ func runUpdateCmd(ctx *cli.Context) {
cli.ShowCommandHelpAndExit(ctx, "update", 1) // last argument is exit code
}
if !isMcConfigExist() {
console.Fatalln(console.ErrorMessage{
console.Fatalln(ErrorMessage{
Message: "Please run \"mc config generate\"",
Error: iodine.New(errors.New("\"mc\" is not configured"), nil),
})
}
hostConfig, err := getHostConfig(mcUpdateURL)
if err != nil {
console.Fatalln(console.ErrorMessage{
console.Fatalln(ErrorMessage{
Message: fmt.Sprintf("Unable to read configuration for host ‘%s’", mcUpdateURL),
Error: iodine.New(err, nil),
})
}
msg, err := doUpdateCheck(hostConfig)
if err != nil {
console.Fatalln(console.ErrorMessage{
console.Fatalln(ErrorMessage{
Message: msg,
Error: iodine.New(err, nil),
})
}
console.Infoln(console.Message(msg))
console.Infoln(msg)
}
+2 -2
View File
@@ -119,13 +119,13 @@ func dodiffdirs(firstClnt client.Client, firstURL, secondURL string, recursive b
switch {
case errFirst != nil && errSecond == nil:
ch <- diff{
message: "Only in ‘" + secondURL + "’",
message: "‘" + newSecondURL + "’ Only in ‘" + secondURL + "’",
err: nil,
}
continue
case errFirst == nil && errSecond != nil:
ch <- diff{
message: "Only in ‘" + firstURL + "’",
message: "‘" + newFirstURL + "’ Only in ‘" + firstURL + "’",
err: nil,
}
continue
+14
View File
@@ -45,3 +45,17 @@ const (
const (
exampleHostURL = "YOUR-EXAMPLE.COM"
)
// ErrorMessage container for message reason encapsulation
type ErrorMessage struct {
Message string
Error error
}
// Content container for content message structure
type Content struct {
Filetype string `json:"ContentType"`
Time string `json:"LastModified"`
Size string `json:"Size"`
Name string `json:"Name"`
}
+37 -16
View File
@@ -17,6 +17,7 @@
package main
import (
"fmt"
"runtime"
"strings"
@@ -33,28 +34,47 @@ const (
printDate = "2006-01-02 15:04:05 MST"
)
// printContent prints content meta-data
func printContent(c *client.Content) {
content := console.Content{}
func (c Content) String() string {
message := console.Time("[%s] ", c.Time)
message = message + console.Size("%6s ", c.Size)
message = func() string {
if c.Filetype == "inode/directory" {
return message + console.Dir("%s", c.Name)
}
return message + console.File("%s", c.Name)
}()
return message
}
func parseContent(c *client.Content) Content {
content := Content{}
content.Time = c.Time.Local().Format(printDate)
content.Filetype = func() string {
if c.Type.IsDir() {
return "inode/directory"
}
if c.Type.IsRegular() {
return "application/octet-stream"
}
return "application/octet-stream"
}()
content.Size = humanize.IBytes(uint64(c.Size))
switch {
case runtime.GOOS == "windows":
content.Name = strings.Replace(c.Name, "/", "\\", -1)
content.Name = strings.TrimSuffix(content.Name, "\\")
default:
content.Name = strings.TrimSuffix(c.Name, "/")
}
content.Time = c.Time.Local().Format(printDate)
console.ContentInfo(content)
content.Name = func() string {
switch {
case runtime.GOOS == "windows":
c.Name = strings.Replace(c.Name, "/", "\\", -1)
c.Name = strings.TrimSuffix(c.Name, "\\")
default:
c.Name = strings.TrimSuffix(c.Name, "/")
}
if c.Type.IsDir() {
switch {
case runtime.GOOS == "windows":
return fmt.Sprintf("%s\\", c.Name)
default:
return fmt.Sprintf("%s/", c.Name)
}
}
return c.Name
}()
return content
}
// doList - list all entities inside a folder
@@ -74,7 +94,8 @@ func doList(clnt client.Client, targetURL string, recursive bool) error {
contentName = strings.TrimPrefix(contentName, strings.TrimSuffix(targetURL, "/")+"/")
}
contentCh.Content.Name = contentName
printContent(contentCh.Content)
content := parseContent(contentCh.Content)
console.Println(content)
}
if err != nil {
return iodine.New(err, map[string]string{"Target": targetURL})
+5 -5
View File
@@ -35,7 +35,7 @@ import (
func checkConfig() {
_, err := user.Current()
if err != nil {
console.Fatalln(console.ErrorMessage{
console.Fatalln(ErrorMessage{
Message: "Unable to determine current user",
Error: err,
})
@@ -49,7 +49,7 @@ func checkConfig() {
// Ensures config file is sane
_, err = getMcConfig()
if err != nil {
console.Fatalln(console.ErrorMessage{
console.Fatalln(ErrorMessage{
Message: fmt.Sprintf("Unable to read config file: %s", mustGetMcConfigPath()),
Error: err,
})
@@ -120,14 +120,14 @@ func main() {
themeName := ctx.GlobalString("theme")
switch {
case console.IsValidTheme(themeName) != true:
console.Fatalln(console.ErrorMessage{
console.Fatalln(ErrorMessage{
Message: fmt.Sprintf("Please choose from this list: %s.", console.GetThemeNames()),
Error: fmt.Errorf("Theme ‘%s’ is not supported.", themeName),
})
default:
err := console.SetTheme(themeName)
if err != nil {
console.Fatalln(console.ErrorMessage{
console.Fatalln(ErrorMessage{
Message: fmt.Sprintf("Failed to set theme ‘%s’.", themeName),
Error: err,
})
@@ -138,7 +138,7 @@ func main() {
}
app.After = func(ctx *cli.Context) error {
if !isMcConfigExist() {
console.Fatalln(console.ErrorMessage{
console.Fatalln(ErrorMessage{
Message: "Please run \"mc config generate\"",
Error: iodine.New(errors.New("\"mc\" is not configured"), nil),
})
+73 -87
View File
@@ -20,12 +20,12 @@ import (
"encoding/json"
"fmt"
"os"
"runtime"
"sync"
"path/filepath"
"github.com/fatih/color"
"github.com/fatih/structs"
"github.com/minio/minio/pkg/iodine"
"github.com/shiena/ansicolor"
)
@@ -36,23 +36,6 @@ var NoDebugPrint = true
// NoJsonPrint defines if the input should be printed in json formatted or not. By default it's set to true.
var NoJSONPrint = true
// Message info string
type Message string
// ErrorMessage error message structure
type ErrorMessage struct {
Message string `json:"Message"`
Error error `json:"Reason"`
}
// Content content message structure
type Content struct {
Filetype string `json:"ContentType"`
Time string `json:"LastModified"`
Size string `json:"Size"`
Name string `json:"Name"`
}
// Theme holds console color scheme
type Theme struct {
Fatal *color.Color
@@ -65,6 +48,17 @@ type Theme struct {
Dir *color.Color
Retry *color.Color
JSON *color.Color
Print *color.Color
}
func readErrordata(data interface{}) (string, error) {
st := structs.New(data)
if st.IsZero() {
return "", nil
}
msg := st.Field("Message")
msgErr := st.Field("Error")
return msg.Value().(string), msgErr.Value().(error)
}
var (
@@ -91,93 +85,114 @@ var (
}()
// Print prints a message
Print = themesDB[currThemeName].Info.Print
Print = func(data interface{}) {
if NoJSONPrint {
print(themesDB[currThemeName].Print, data)
return
}
printBytes, _ := json.Marshal(&data)
print(themesDB[currThemeName].JSON, string(printBytes))
}
// Println prints a message with a newline
Println = func(data interface{}) {
if NoJSONPrint {
println(themesDB[currThemeName].Print, data)
return
}
printBytes, _ := json.Marshal(&data)
println(themesDB[currThemeName].JSON, string(printBytes))
}
// Fatal prints a error message and exits
Fatal = func(msg ErrorMessage) {
Fatal = func(data interface{}) {
defer os.Exit(1)
if msg.Error != nil {
msg, err := readErrordata(data)
if err != nil {
if NoJSONPrint {
reason := "Reason: " + iodine.ToError(msg.Error).Error()
message := msg.Message + ", " + reason
reason := "Reason: " + iodine.ToError(err).Error()
message := msg + ", " + reason
print(themesDB[currThemeName].Error, message)
if !NoDebugPrint {
print(themesDB[currThemeName].Error, msg.Error)
print(themesDB[currThemeName].Error, err)
}
return
}
errorMessageBytes, _ := json.Marshal(&msg)
errorMessageBytes, _ := json.Marshal(&data)
print(themesDB[currThemeName].JSON, string(errorMessageBytes))
}
}
// Fatalln prints a error message with a new line and exits
Fatalln = func(msg ErrorMessage) {
Fatalln = func(data interface{}) {
defer os.Exit(1)
if msg.Error != nil {
msg, err := readErrordata(data)
if err != nil {
if NoJSONPrint {
reason := "Reason: " + iodine.ToError(msg.Error).Error()
message := msg.Message + ", " + reason
reason := "Reason: " + iodine.ToError(err).Error()
message := msg + ", " + reason
println(themesDB[currThemeName].Error, message)
if !NoDebugPrint {
println(themesDB[currThemeName].Error, msg.Error)
println(themesDB[currThemeName].Error, err)
}
return
}
errorMessageBytes, _ := json.Marshal(&msg)
errorMessageBytes, _ := json.Marshal(&data)
println(themesDB[currThemeName].JSON, string(errorMessageBytes))
}
}
// Error prints a error message
Error = func(msg ErrorMessage) {
if msg.Error != nil {
Error = func(data interface{}) {
msg, err := readErrordata(data)
if err != nil {
if NoJSONPrint {
reason := "Reason: " + iodine.ToError(msg.Error).Error()
message := msg.Message + ", " + reason
reason := "Reason: " + iodine.ToError(err).Error()
message := msg + ", " + reason
print(themesDB[currThemeName].Error, message)
if !NoDebugPrint {
print(themesDB[currThemeName].Error, msg.Error)
print(themesDB[currThemeName].Error, err)
}
return
}
errorMessageBytes, _ := json.Marshal(&msg)
errorMessageBytes, _ := json.Marshal(&data)
print(themesDB[currThemeName].JSON, string(errorMessageBytes))
}
}
// Errorln prints a error message with a new line
Errorln = func(msg ErrorMessage) {
if msg.Error != nil {
Errorln = func(data interface{}) {
msg, err := readErrordata(data)
if err != nil {
if NoJSONPrint {
reason := "Reason: " + iodine.ToError(msg.Error).Error()
message := msg.Message + ", " + reason
reason := "Reason: " + iodine.ToError(err).Error()
message := msg + ", " + reason
println(themesDB[currThemeName].Error, message)
if !NoDebugPrint {
println(themesDB[currThemeName].Error, msg.Error)
println(themesDB[currThemeName].Error, err)
}
return
}
errorMessageBytes, _ := json.Marshal(&msg)
errorMessageBytes, _ := json.Marshal(&data)
println(themesDB[currThemeName].JSON, string(errorMessageBytes))
}
}
// Info prints a informational message
Info = func(msg Message) {
Info = func(data interface{}) {
if NoJSONPrint {
print(themesDB[currThemeName].Info, msg)
print(themesDB[currThemeName].Info, data)
return
}
infoBytes, _ := json.Marshal(&msg)
infoBytes, _ := json.Marshal(&data)
print(themesDB[currThemeName].JSON, string(infoBytes))
}
// Infoln prints a informational message with a new line
Infoln = func(msg Message) {
Infoln = func(data interface{}) {
if NoJSONPrint {
println(themesDB[currThemeName].Info, msg)
println(themesDB[currThemeName].Info, data)
return
}
infoBytes, _ := json.Marshal(&msg)
infoBytes, _ := json.Marshal(&data)
println(themesDB[currThemeName].JSON, string(infoBytes))
}
@@ -195,22 +210,15 @@ var (
println(themesDB[currThemeName].Debug, a...)
}
}
// ContentInfo prints a structure Content
ContentInfo = func(c Content) {
if NoJSONPrint {
print(themesDB[currThemeName].Time, c.Time)
print(themesDB[currThemeName].Size, c.Size)
switch c.Filetype {
case "inode/directory":
println(themesDB[currThemeName].Dir, c.Name)
case "application/octet-stream":
println(themesDB[currThemeName].File, c.Name)
}
return
}
contentBytes, _ := json.Marshal(&c)
println(themesDB[currThemeName].JSON, string(contentBytes))
}
// Time helper to print Time theme
Time = themesDB[currThemeName].Time.SprintfFunc()
// Size helper to print Size theme
Size = themesDB[currThemeName].Size.SprintfFunc()
// File helper to print File theme
File = themesDB[currThemeName].File.SprintfFunc()
// Dir helper to print Dir theme
Dir = themesDB[currThemeName].Dir.SprintfFunc()
// Retry prints a retry message
Retry = func(a ...interface{}) {
@@ -252,15 +260,6 @@ var (
c.Print(ProgramName() + ": ")
c.Print(a...)
mutex.Unlock()
// special cases only for Content where it requires custom formatting
case themesDB[currThemeName].Time:
mutex.Lock()
c.Print(fmt.Sprintf("[%s] ", a...))
mutex.Unlock()
case themesDB[currThemeName].Size:
mutex.Lock()
c.Printf(fmt.Sprintf("%6s ", a...))
mutex.Unlock()
default:
mutex.Lock()
c.Print(a...)
@@ -300,19 +299,6 @@ var (
c.Print(ProgramName() + ": ")
c.Println(a...)
mutex.Unlock()
case themesDB[currThemeName].Dir:
mutex.Lock()
switch {
case runtime.GOOS == "windows":
c.Printf("%s\\\n", a...)
default:
c.Printf("%s/\n", a...)
}
mutex.Unlock()
case themesDB[currThemeName].File:
mutex.Lock()
c.Println(a...)
mutex.Unlock()
default:
mutex.Lock()
c.Println(a...)
+3
View File
@@ -30,6 +30,7 @@ var MiniTheme = Theme{
Time: (color.New(color.FgGreen)),
Retry: (color.New(color.FgMagenta, color.Bold)),
JSON: (color.New(color.FgWhite, color.Italic)),
Print: (color.New()),
}
// WhiteTheme - All white color theme
@@ -44,6 +45,7 @@ var WhiteTheme = Theme{
Time: (color.New(color.FgWhite, color.Bold)),
Retry: (color.New(color.FgWhite, color.Bold)),
JSON: (color.New(color.FgWhite, color.Bold, color.Italic)),
Print: (color.New()),
}
// NoColorTheme - Disables color theme
@@ -58,4 +60,5 @@ var NoColorTheme = Theme{
Time: (color.New()),
Retry: (color.New()),
JSON: (color.New()),
Print: (color.New()),
}