Merge pull request #1024 from abperiasamy/diff-err-update
diff error handling update
This commit is contained in:
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
* Minio Client (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.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
// DiffMessage json container for diff messages
|
||||
type DiffMessage struct {
|
||||
FirstURL string `json:"first"`
|
||||
SecondURL string `json:"second"`
|
||||
Diff string `json:"diff"`
|
||||
}
|
||||
|
||||
func (d DiffMessage) String() string {
|
||||
if !globalJSONFlag {
|
||||
var message string
|
||||
if d.Diff == "Only-in" {
|
||||
message = "‘" + d.FirstURL + "’ Only in ‘" + d.SecondURL + "’\n"
|
||||
}
|
||||
if d.Diff == "Type" {
|
||||
message = d.FirstURL + " and " + d.SecondURL + " differs in type.\n"
|
||||
}
|
||||
if d.Diff == "Size" {
|
||||
message = d.FirstURL + " and " + d.SecondURL + " differs in size.\n"
|
||||
}
|
||||
return message
|
||||
}
|
||||
diffJSONBytes, err := json.Marshal(d)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return string(diffJSONBytes) + "\n"
|
||||
}
|
||||
+7
-6
@@ -17,9 +17,10 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/minio/mc/internal/github.com/minio/cli"
|
||||
"github.com/minio/mc/internal/github.com/minio/minio/pkg/probe"
|
||||
"github.com/minio/mc/pkg/console"
|
||||
)
|
||||
|
||||
// Help message.
|
||||
@@ -63,19 +64,19 @@ func mainDiff(ctx *cli.Context) {
|
||||
|
||||
var err *probe.Error
|
||||
firstURL, err = getCanonicalizedURL(firstURL, config.Aliases)
|
||||
fatalIf(err.Trace(), "Unable to canonicalize first URL.")
|
||||
fatalIf(err.Trace(firstURL), "Unable to canonicalize first URL.")
|
||||
|
||||
secondURL, err = getCanonicalizedURL(secondURL, config.Aliases)
|
||||
fatalIf(err.Trace(), "Unable to canonicalize second URL.")
|
||||
fatalIf(err.Trace(secondURL), "Unable to canonicalize second URL.")
|
||||
|
||||
if isURLRecursive(secondURL) {
|
||||
console.Fatalf("Second URL cannot be recursive. %s\n", errInvalidArgument)
|
||||
fatalIf(probe.NewError(errInvalidArgument), "Second argument ‘"+secondURL+"’ cannot be recursive.")
|
||||
}
|
||||
newFirstURL := stripRecursiveURL(firstURL)
|
||||
for diff := range doDiffCmd(newFirstURL, secondURL, isURLRecursive(firstURL)) {
|
||||
fatalIf(diff.err.Trace(), diff.message)
|
||||
fatalIf(diff.err.Trace(newFirstURL, secondURL), "Failed to diff ‘"+firstURL+"’ and ‘"+secondURL+"’.")
|
||||
fmt.Println(diff.message)
|
||||
}
|
||||
console.Println()
|
||||
}
|
||||
|
||||
// doDiffCmd - Execute the diff command
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -43,6 +45,34 @@ import (
|
||||
// 2. diff(d1..., d2...) -> INVALID
|
||||
//
|
||||
|
||||
// DiffMessage json container for diff messages
|
||||
type DiffMessage struct {
|
||||
FirstURL string `json:"first"`
|
||||
SecondURL string `json:"second"`
|
||||
Diff string `json:"diff"`
|
||||
}
|
||||
|
||||
func (d DiffMessage) String() string {
|
||||
if !globalJSONFlag {
|
||||
msg := ""
|
||||
switch d.Diff {
|
||||
case "Only-in":
|
||||
msg = "‘" + d.FirstURL + "’ only in ‘" + d.SecondURL + "’."
|
||||
case "Type":
|
||||
msg = d.FirstURL + " and " + d.SecondURL + " differs in type."
|
||||
case "Size":
|
||||
msg = d.FirstURL + " and " + d.SecondURL + " differs in size."
|
||||
default:
|
||||
fatalIf(probe.NewError(errors.New("")), "Unhandled difference between ‘"+d.FirstURL+"’ and ‘"+d.SecondURL+"’.")
|
||||
}
|
||||
return msg
|
||||
}
|
||||
diffJSONBytes, err := json.Marshal(d)
|
||||
fatalIf(probe.NewError(err), "Unable to marshal diff message ‘"+d.FirstURL+"’, ‘"+d.SecondURL+"’ and ‘"+d.Diff+"’.")
|
||||
|
||||
return string(diffJSONBytes)
|
||||
}
|
||||
|
||||
type diff struct {
|
||||
message string
|
||||
err *probe.Error
|
||||
|
||||
Reference in New Issue
Block a user