From 7e7fcb35eaffe88718660b9fac5fbd5aeee5f03e Mon Sep 17 00:00:00 2001 From: Jeromy Date: Sat, 16 Apr 2016 12:23:34 -0700 Subject: [PATCH] changes from CR feedback License: MIT Signed-off-by: Jeromy --- core/commands/object/diff.go | 32 +++++++++++++++++++++++------- core/commands/object/object.go | 4 ++-- test/sharness/t0052-object-diff.sh | 15 +++++++++++--- 3 files changed, 39 insertions(+), 12 deletions(-) diff --git a/core/commands/object/diff.go b/core/commands/object/diff.go index d2b72ca20..83dc04e59 100644 --- a/core/commands/object/diff.go +++ b/core/commands/object/diff.go @@ -15,6 +15,9 @@ var ObjectDiffCmd = &cmds.Command{ Tagline: "takes a diff of the two given objects", ShortDescription: ` ipfs object diff is a command used to show the differences between +two ipfs objects.`, + LongDescription: ` +ipfs object diff is a command used to show the differences between two ipfs objects. Example: @@ -38,6 +41,9 @@ Example: cmds.StringArg("obj_a", true, false, "object to diff against"), cmds.StringArg("obj_b", true, false, "object to diff"), }, + Options: []cmds.Option{ + cmds.BoolOption("verbose", "v", "Produce verbose output"), + }, Run: func(req cmds.Request, res cmds.Response) { node, err := req.InvocContext().GetNode() if err != nil { @@ -85,16 +91,28 @@ Example: Type: []*dagutils.Change{}, Marshalers: cmds.MarshalerMap{ cmds.Text: func(res cmds.Response) (io.Reader, error) { + verbose, _, _ := res.Request().Option("v").Bool() changes := res.Output().([]*dagutils.Change) buf := new(bytes.Buffer) for _, change := range changes { - switch change.Type { - case dagutils.Add: - fmt.Fprintf(buf, "added new link %q pointing to %s\n", change.Path, change.After) - case dagutils.Mod: - fmt.Fprintf(buf, "changed %q from %s to %s\n", change.Path, change.Before, change.After) - case dagutils.Remove: - fmt.Fprintf(buf, "removed link %q (was %s)\n", change.Path, change.Before) + if verbose { + switch change.Type { + case dagutils.Add: + fmt.Fprintf(buf, "added new link %q pointing to %s\n", change.Path, change.After) + case dagutils.Mod: + fmt.Fprintf(buf, "changed %q from %s to %s\n", change.Path, change.Before, change.After) + case dagutils.Remove: + fmt.Fprintf(buf, "removed link %q (was %s)\n", change.Path, change.Before) + } + } else { + switch change.Type { + case dagutils.Add: + fmt.Fprintf(buf, "+ %s %q\n", change.After, change.Path) + case dagutils.Mod: + fmt.Fprintf(buf, "~ %s %s %q\n", change.Before, change.After, change.Path) + case dagutils.Remove: + fmt.Fprintf(buf, "- %s %q\n", change.Before, change.Path) + } } } return buf, nil diff --git a/core/commands/object/object.go b/core/commands/object/object.go index f39b35d09..7ab8bf949 100644 --- a/core/commands/object/object.go +++ b/core/commands/object/object.go @@ -49,25 +49,25 @@ var ObjectCmd = &cmds.Command{ directly.`, Synopsis: ` ipfs object data - Outputs raw bytes in an object +ipfs object diff - Diffs two given objects ipfs object get - Get the DAG node named by ipfs object links - Outputs links pointed to by object ipfs object new