From 201bddaeb10627c42f622aaf72a745e0cda02cb5 Mon Sep 17 00:00:00 2001 From: Thomas Osterbind Date: Tue, 6 Feb 2018 09:21:58 -0500 Subject: [PATCH] fix: updated cmd.diff to be compatible with updates to datasetDiffer --- cmd/cmd_test.go | 6 +++++- cmd/diff.go | 36 +++++++++++++++++++++++++++++------- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/cmd/cmd_test.go b/cmd/cmd_test.go index ea0d0affd..5df07ee8a 100644 --- a/cmd/cmd_test.go +++ b/cmd/cmd_test.go @@ -58,6 +58,10 @@ const profileData = ` // This is a basic integration test that makes sure basic happy paths work on the CLI func TestCommandsIntegration(t *testing.T) { path := filepath.Join(os.TempDir(), "qri_test_commands_integration") + //clean up if previous cleanup failed + if _, err := os.Stat(path); os.IsNotExist(err) { + os.RemoveAll(path) + } if err := os.MkdirAll(path, os.ModePerm); err != nil { t.Errorf("error creating test path: %s", err.Error()) return @@ -101,7 +105,7 @@ func TestCommandsIntegration(t *testing.T) { {"list"}, {"save", "--data=" + movies2FilePath, "-t" + "commit_1", "me/movies"}, {"log", "me/movies"}, - {"diff", "me/movies", "me/movies2"}, + {"diff", "me/movies", "me/movies2", "-d", "detail"}, {"export", "--dataset", "me/movies", "-o" + path}, {"rename", "me/movies", "me/movie"}, {"validate", "me/movie"}, diff --git a/cmd/diff.go b/cmd/diff.go index 3c10997ce..a5b30ba2d 100644 --- a/cmd/diff.go +++ b/cmd/diff.go @@ -8,17 +8,22 @@ import ( "github.com/qri-io/qri/core" "github.com/qri-io/qri/repo" "github.com/spf13/cobra" - diff "github.com/yudai/gojsondiff" + // diff "github.com/yudai/gojsondiff" ) var datasetDiffCmd = &cobra.Command{ Use: "diff", Short: "diff two datasets", Long: ` -Diff diffs two datasets`, +Diff compares two datasets from your repo and prints a represntation +of the differences between them. You can specifify the datasets +either by name or by their hash`, Example: `todo`, Run: func(cmd *cobra.Command, args []string) { - if len(args) != 2 { + for i, arg := range args { + fmt.Printf("%d: %s\n", i, arg) + } + if len(args) < 2 { ErrExit(fmt.Errorf("please provide names for two datsets")) } @@ -40,7 +45,7 @@ Diff diffs two datasets`, err = req.Get(rightRef, right) ExitIfErr(err) - diffs := &map[string]diff.Diff{} + diffs := make(map[string]*datasetDiffer.SubDiff) p := &core.DiffParams{ DsLeft: left.Dataset, @@ -48,13 +53,30 @@ Diff diffs two datasets`, DiffAll: true, } - err = req.Diff(p, diffs) + err = req.Diff(p, &diffs) ExitIfErr(err) - - fmt.Println(datasetDiffer.MapDiffsToString(*diffs)) + displayFormat := "listKeys" + displayFlag := cmd.Flag("display").Value.String() + if displayFlag != "" { + switch displayFlag { + case "reg", "regular": + displayFormat = "listKeys" + case "short", "s": + displayFormat = "simple" + case "delta": + displayFormat = "delta" + case "detail": + displayFormat = "plusMinus" + } + } + result, err := datasetDiffer.MapDiffsToString(diffs, displayFormat) + ExitIfErr(err) + fmt.Println(result) }, } func init() { RootCmd.AddCommand(datasetDiffCmd) + datasetDiffCmd.Flags().StringP("display", "d", "", "set display format [reg|short|delta|detail]") + // datasetDiffCmd.Flags().BoolP("color", "c", false, "set ") }