Add more structured informational messages

This commit is contained in:
Harshavardhana
2015-06-22 11:33:14 -07:00
parent d99063a11f
commit 1dbb2e2b96
6 changed files with 25 additions and 11 deletions
+6 -3
View File
@@ -100,13 +100,16 @@ func runAccessCmd(ctx *cli.Context) {
})
}
}
errorMsg, err := doUpdateAccessCmd(targetURL, acl)
msg, err := doUpdateAccessCmd(targetURL, acl)
if err != nil {
console.Errors(ErrorMessage{
Message: errorMsg,
Message: msg,
Error: iodine.New(err, nil),
})
}
console.Infos(InfoMessage{
Message: msg,
})
}
}
@@ -127,5 +130,5 @@ func doUpdateAccess(clnt client.Client, targetACL bucketACL) (string, error) {
msg := fmt.Sprintf("Failed to add bucket access policy for URL ‘%s’", clnt.URL().String())
return msg, iodine.New(err, nil)
}
return "", nil
return "Bucket access policy updated successfully : " + clnt.URL().String(), nil
}
+3 -1
View File
@@ -77,7 +77,9 @@ func runConfigCmd(ctx *cli.Context) {
Error: err,
})
}
console.Infoln(msg)
console.Infos(InfoMessage{
Message: msg,
})
}
// saveConfig writes configuration data in json format to config file.
+3 -1
View File
@@ -119,7 +119,9 @@ func runDiffCmd(ctx *cli.Context) {
Error: diff.err,
})
}
console.Infoln(diff.message)
console.Infos(InfoMessage{
Message: diff.message,
})
}
}
+6 -3
View File
@@ -89,13 +89,16 @@ func runMakeBucketCmd(ctx *cli.Context) {
})
}
}
errorMsg, err := doMakeBucketCmd(targetURL)
msg, err := doMakeBucketCmd(targetURL)
if err != nil {
console.Errors(ErrorMessage{
Message: errorMsg,
Message: msg,
Error: iodine.New(err, nil),
})
}
console.Infos(InfoMessage{
Message: msg,
})
}
}
@@ -118,5 +121,5 @@ func doMakeBucket(clnt client.Client) (string, error) {
msg := fmt.Sprintf("Failed to create bucket for URL ‘%s’", clnt.URL().String())
return msg, iodine.New(err, nil)
}
return "", nil
return "Bucket created successfully : " + clnt.URL().String(), nil
}
+3 -3
View File
@@ -51,7 +51,7 @@ type Theme struct {
Print *color.Color
}
func readErrorFromdata(data interface{}) error {
func readErrorFromData(data interface{}) error {
st := structs.New(data)
if st.IsZero() {
return nil
@@ -176,7 +176,7 @@ var (
Fatals = func(data ...interface{}) {
defer os.Exit(1)
for i := 0; i < len(data); i++ {
err := readErrorFromdata(data[i])
err := readErrorFromData(data[i])
if err != nil {
if NoJSONPrint {
println(themesDB[currThemeName].Error, data[i])
@@ -230,7 +230,7 @@ var (
// Errors print a error structure with a new line
Errors = func(data ...interface{}) {
for i := 0; i < len(data); i++ {
err := readErrorFromdata(data[i])
err := readErrorFromData(data[i])
if err != nil {
if NoJSONPrint {
println(themesDB[currThemeName].Error, data[i])
+4
View File
@@ -67,3 +67,7 @@ func (c Content) String() string {
type InfoMessage struct {
Message string `json:"message"`
}
func (i InfoMessage) String() string {
return i.Message
}