mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-27 16:07:42 +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",
|
Tagline: "takes a diff of the two given objects",
|
||||||
ShortDescription: `
|
ShortDescription: `
|
||||||
ipfs object diff is a command used to show the differences between
|
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.
|
two ipfs objects.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
@ -38,6 +41,9 @@ Example:
|
|||||||
cmds.StringArg("obj_a", true, false, "object to diff against"),
|
cmds.StringArg("obj_a", true, false, "object to diff against"),
|
||||||
cmds.StringArg("obj_b", true, false, "object to diff"),
|
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) {
|
Run: func(req cmds.Request, res cmds.Response) {
|
||||||
node, err := req.InvocContext().GetNode()
|
node, err := req.InvocContext().GetNode()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -85,9 +91,11 @@ Example:
|
|||||||
Type: []*dagutils.Change{},
|
Type: []*dagutils.Change{},
|
||||||
Marshalers: cmds.MarshalerMap{
|
Marshalers: cmds.MarshalerMap{
|
||||||
cmds.Text: func(res cmds.Response) (io.Reader, error) {
|
cmds.Text: func(res cmds.Response) (io.Reader, error) {
|
||||||
|
verbose, _, _ := res.Request().Option("v").Bool()
|
||||||
changes := res.Output().([]*dagutils.Change)
|
changes := res.Output().([]*dagutils.Change)
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
for _, change := range changes {
|
for _, change := range changes {
|
||||||
|
if verbose {
|
||||||
switch change.Type {
|
switch change.Type {
|
||||||
case dagutils.Add:
|
case dagutils.Add:
|
||||||
fmt.Fprintf(buf, "added new link %q pointing to %s\n", change.Path, change.After)
|
fmt.Fprintf(buf, "added new link %q pointing to %s\n", change.Path, change.After)
|
||||||
@ -96,6 +104,16 @@ Example:
|
|||||||
case dagutils.Remove:
|
case dagutils.Remove:
|
||||||
fmt.Fprintf(buf, "removed link %q (was %s)\n", change.Path, change.Before)
|
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
|
return buf, nil
|
||||||
},
|
},
|
||||||
|
@ -49,25 +49,25 @@ var ObjectCmd = &cmds.Command{
|
|||||||
directly.`,
|
directly.`,
|
||||||
Synopsis: `
|
Synopsis: `
|
||||||
ipfs object data <key> - Outputs raw bytes in an object
|
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 get <key> - Get the DAG node named by <key>
|
||||||
ipfs object links <key> - Outputs links pointed to by object
|
ipfs object links <key> - Outputs links pointed to by object
|
||||||
ipfs object new <template> - Create new ipfs objects
|
ipfs object new <template> - Create new ipfs objects
|
||||||
ipfs object patch <args> - Create new object from old ones
|
ipfs object patch <args> - Create new object from old ones
|
||||||
ipfs object put <data> - Stores input, outputs its key
|
ipfs object put <data> - Stores input, outputs its key
|
||||||
ipfs object stat <key> - Outputs statistics of object
|
ipfs object stat <key> - Outputs statistics of object
|
||||||
ipfs object diff <key1> <key2> - Diffs two given objects
|
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
|
|
||||||
Subcommands: map[string]*cmds.Command{
|
Subcommands: map[string]*cmds.Command{
|
||||||
"data": ObjectDataCmd,
|
"data": ObjectDataCmd,
|
||||||
|
"diff": ObjectDiffCmd,
|
||||||
"get": ObjectGetCmd,
|
"get": ObjectGetCmd,
|
||||||
"links": ObjectLinksCmd,
|
"links": ObjectLinksCmd,
|
||||||
"new": ObjectNewCmd,
|
"new": ObjectNewCmd,
|
||||||
"patch": ObjectPatchCmd,
|
"patch": ObjectPatchCmd,
|
||||||
"put": ObjectPutCmd,
|
"put": ObjectPutCmd,
|
||||||
"stat": ObjectStatCmd,
|
"stat": ObjectStatCmd,
|
||||||
"diff": ObjectDiffCmd,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,12 +37,21 @@ test_expect_success "diff added link works" '
|
|||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success "diff added link looks right" '
|
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 &&
|
echo added new link \"cat\" pointing to QmUSvcqzhdfYM1KLDbM76eLPdS9ANFtkJvFuPYeZt73d7A > diff_exp &&
|
||||||
test_cmp diff_exp diff_out
|
test_cmp diff_exp diff_out
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success "diff removed link works" '
|
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" '
|
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" '
|
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" '
|
test_expect_success "diff looks right" '
|
||||||
@ -60,7 +69,7 @@ test_expect_success "diff looks right" '
|
|||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success "diff changed link works" '
|
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" '
|
test_expect_success "diff looks right" '
|
||||||
|
Reference in New Issue
Block a user