@cryptotaxi247 / kubo / commits / 7e7fcb35e

changes from CR feedback

License: MIT Signed-off-by: Jeromy <why@ipfs.io>

Jeromy committed Apr 16, 2016 at 12:23 UTC 7e7fcb35eaffe88718660b9fac5fbd5aeee5f03e
3 files changed +39 -12
core/commands/object/diff.go
+25 -7
@@ -15,6 +15,9 @@ var ObjectDiffCmd = &cmds.Command{
15 Tagline: "takes a diff of the two given objects",
16 ShortDescription: `
17 ipfs object diff is a command used to show the differences between
18 +two ipfs objects.`,
19 + LongDescription: `
20 +ipfs object diff is a command used to show the differences between
21 two ipfs objects.
22
23 Example:
@@ -38,6 +41,9 @@ Example:
41 cmds.StringArg("obj_a", true, false, "object to diff against"),
42 cmds.StringArg("obj_b", true, false, "object to diff"),
43 },
44 + Options: []cmds.Option{
45 + cmds.BoolOption("verbose", "v", "Produce verbose output"),
46 + },
47 Run: func(req cmds.Request, res cmds.Response) {
48 node, err := req.InvocContext().GetNode()
49 if err != nil {
@@ -85,16 +91,28 @@ Example:
91 Type: []*dagutils.Change{},
92 Marshalers: cmds.MarshalerMap{
93 cmds.Text: func(res cmds.Response) (io.Reader, error) {
94 + verbose, _, _ := res.Request().Option("v").Bool()
95 changes := res.Output().([]*dagutils.Change)
96 buf := new(bytes.Buffer)
97 for _, change := range changes {
91 - switch change.Type {
92 - case dagutils.Add:
93 - fmt.Fprintf(buf, "added new link %q pointing to %s\n", change.Path, change.After)
94 - case dagutils.Mod:
95 - fmt.Fprintf(buf, "changed %q from %s to %s\n", change.Path, change.Before, change.After)
96 - case dagutils.Remove:
97 - fmt.Fprintf(buf, "removed link %q (was %s)\n", change.Path, change.Before)
98 + if verbose {
99 + switch change.Type {
100 + case dagutils.Add:
101 + fmt.Fprintf(buf, "added new link %q pointing to %s\n", change.Path, change.After)
102 + case dagutils.Mod:
103 + fmt.Fprintf(buf, "changed %q from %s to %s\n", change.Path, change.Before, change.After)
104 + case dagutils.Remove:
105 + fmt.Fprintf(buf, "removed link %q (was %s)\n", change.Path, change.Before)
106 + }
107 + } else {
108 + switch change.Type {
109 + case dagutils.Add:
110 + fmt.Fprintf(buf, "+ %s %q\n", change.After, change.Path)
111 + case dagutils.Mod:
112 + fmt.Fprintf(buf, "~ %s %s %q\n", change.Before, change.After, change.Path)
113 + case dagutils.Remove:
114 + fmt.Fprintf(buf, "- %s %q\n", change.Before, change.Path)
115 + }
116 }
117 }
118 return buf, nil
core/commands/object/object.go
+2 -2
@@ -49,25 +49,25 @@ var ObjectCmd = &cmds.Command{
49 directly.`,
50 Synopsis: `
51 ipfs object data <key> - Outputs raw bytes in an object
52 +ipfs object diff <key1> <key2> - Diffs two given objects
53 ipfs object get <key> - Get the DAG node named by <key>
54 ipfs object links <key> - Outputs links pointed to by object
55 ipfs object new <template> - Create new ipfs objects
56 ipfs object patch <args> - Create new object from old ones
57 ipfs object put <data> - Stores input, outputs its key
58 ipfs object stat <key> - Outputs statistics of object
58 -ipfs object diff <key1> <key2> - Diffs two given objects
59 `,
60 },
61
62 Subcommands: map[string]*cmds.Command{
63 "data": ObjectDataCmd,
64 + "diff": ObjectDiffCmd,
65 "get": ObjectGetCmd,
66 "links": ObjectLinksCmd,
67 "new": ObjectNewCmd,
68 "patch": ObjectPatchCmd,
69 "put": ObjectPutCmd,
70 "stat": ObjectStatCmd,
70 - "diff": ObjectDiffCmd,
71 },
72 }
73
test/sharness/t0052-object-diff.sh
+12 -3
@@ -37,12 +37,21 @@ test_expect_success "diff added link works" '
37 '
38
39 test_expect_success "diff added link looks right" '
40 + echo + QmUSvcqzhdfYM1KLDbM76eLPdS9ANFtkJvFuPYeZt73d7A \"cat\" > diff_exp &&
41 + test_cmp diff_exp diff_out
42 +'
43 +
44 +test_expect_success "verbose diff added link works" '
45 + ipfs object diff -v $A $B > diff_out
46 +'
47 +
48 +test_expect_success "verbose diff added link looks right" '
49 echo added new link \"cat\" pointing to QmUSvcqzhdfYM1KLDbM76eLPdS9ANFtkJvFuPYeZt73d7A > diff_exp &&
50 test_cmp diff_exp diff_out
51 '
52
53 test_expect_success "diff removed link works" '
45 - ipfs object diff $B $A > diff_out
54 + ipfs object diff -v $B $A > diff_out
55 '
56
57 test_expect_success "diff removed link looks right" '
@@ -51,7 +60,7 @@ test_expect_success "diff removed link looks right" '
60 '
61
62 test_expect_success "diff nested add works" '
54 - ipfs object diff $B $C > diff_out
63 + ipfs object diff -v $B $C > diff_out
64 '
65
66 test_expect_success "diff looks right" '
@@ -60,7 +69,7 @@ test_expect_success "diff looks right" '
69 '
70
71 test_expect_success "diff changed link works" '
63 - ipfs object diff $C $D > diff_out
72 + ipfs object diff -v $C $D > diff_out
73 '
74
75 test_expect_success "diff looks right" '