1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-26 23:53:19 +08:00

changes from CR feedback

License: MIT
Signed-off-by: Jeromy <why@ipfs.io>
This commit is contained in:
Jeromy
2016-04-16 12:23:34 -07:00
parent 73a2f80c76
commit 7e7fcb35ea
3 changed files with 39 additions and 12 deletions

View File

@ -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

View File

@ -49,25 +49,25 @@ var ObjectCmd = &cmds.Command{
directly.`,
Synopsis: `
ipfs object data <key> - Outputs raw bytes in an object
ipfs object diff <key1> <key2> - Diffs two given objects
ipfs object get <key> - Get the DAG node named by <key>
ipfs object links <key> - Outputs links pointed to by object
ipfs object new <template> - Create new ipfs objects
ipfs object patch <args> - Create new object from old ones
ipfs object put <data> - Stores input, outputs its key
ipfs object stat <key> - Outputs statistics of object
ipfs object diff <key1> <key2> - Diffs two given objects
`,
},
Subcommands: map[string]*cmds.Command{
"data": ObjectDataCmd,
"diff": ObjectDiffCmd,
"get": ObjectGetCmd,
"links": ObjectLinksCmd,
"new": ObjectNewCmd,
"patch": ObjectPatchCmd,
"put": ObjectPutCmd,
"stat": ObjectStatCmd,
"diff": ObjectDiffCmd,
},
}

View File

@ -37,12 +37,21 @@ test_expect_success "diff added link works" '
'
test_expect_success "diff added link looks right" '
echo + QmUSvcqzhdfYM1KLDbM76eLPdS9ANFtkJvFuPYeZt73d7A \"cat\" > diff_exp &&
test_cmp diff_exp diff_out
'
test_expect_success "verbose diff added link works" '
ipfs object diff -v $A $B > diff_out
'
test_expect_success "verbose diff added link looks right" '
echo added new link \"cat\" pointing to QmUSvcqzhdfYM1KLDbM76eLPdS9ANFtkJvFuPYeZt73d7A > diff_exp &&
test_cmp diff_exp diff_out
'
test_expect_success "diff removed link works" '
ipfs object diff $B $A > diff_out
ipfs object diff -v $B $A > diff_out
'
test_expect_success "diff removed link looks right" '
@ -51,7 +60,7 @@ test_expect_success "diff removed link looks right" '
'
test_expect_success "diff nested add works" '
ipfs object diff $B $C > diff_out
ipfs object diff -v $B $C > diff_out
'
test_expect_success "diff looks right" '
@ -60,7 +69,7 @@ test_expect_success "diff looks right" '
'
test_expect_success "diff changed link works" '
ipfs object diff $C $D > diff_out
ipfs object diff -v $C $D > diff_out
'
test_expect_success "diff looks right" '