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:
@ -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
|
||||
|
@ -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,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -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" '
|
||||
|
Reference in New Issue
Block a user