提交 66686e66 作者: Jakub Sztandera

commands: fix refs 'edges' option work

also change it to use format instead of separate variable

License: MIT
Signed-off-by: 's avatarJakub Sztandera <kubuxu@protonmail.ch>
上级 0bd8ced0
......@@ -74,17 +74,26 @@ NOTE: List all references recursively by using the flag '-r'.
return
}
edges, _, err := req.Option("edges").Bool()
format, _, err := req.Option("format").String()
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
format, _, err := req.Option("format").String()
edges, _, err := req.Option("edges").Bool()
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
if edges {
if format != "<dst>" {
res.SetError(errors.New("using format arguement with edges is not allowed"),
cmds.ErrClient)
return
}
format = "<src> -> <dst>"
}
objs, err := objectsForPaths(ctx, n, req.Arguments())
if err != nil {
......@@ -103,7 +112,6 @@ NOTE: List all references recursively by using the flag '-r'.
DAG: n.DAG,
Ctx: ctx,
Unique: unique,
PrintEdge: edges,
PrintFmt: format,
Recursive: recursive,
}
......@@ -210,7 +218,6 @@ type RefWriter struct {
Unique bool
Recursive bool
PrintEdge bool
PrintFmt string
seen map[key.Key]struct{}
......@@ -315,8 +322,6 @@ func (rw *RefWriter) WriteEdge(from, to key.Key, linkname string) error {
s = strings.Replace(s, "<src>", from.B58String(), -1)
s = strings.Replace(s, "<dst>", to.B58String(), -1)
s = strings.Replace(s, "<linkname>", linkname, -1)
case rw.PrintEdge:
s = from.B58String() + " -> " + to.B58String()
default:
s += to.B58String()
}
......
......@@ -4,8 +4,6 @@ test_description="Tests for various fixed issues and regressions."
. lib/test-lib.sh
test_init_ipfs
# Tests go here
test_expect_success "ipfs init with occupied input works - #2748" '
......@@ -13,6 +11,7 @@ test_expect_success "ipfs init with occupied input works - #2748" '
echo "" | time-out ipfs init &&
rm -rf ipfs_path
'
test_init_ipfs
test_expect_success "ipfs cat --help succeeds with no input" '
time-out ipfs cat --help
......@@ -22,4 +21,22 @@ test_expect_success "ipfs pin ls --help succeeds with no input" '
time-out ipfs pin ls --help
'
test_expect_success "ipfs add on 1MB from stdin woks" '
random 1048576 42 | ipfs add -q > 1MB.hash
'
test_expect_success "'ipfs refs -r -e \$(cat 1MB.hash)' succeeds" '
ipfs refs -r -e $(cat 1MB.hash) > refs-e.out
'
test_expect_success "output of 'ipfs refs -e' links to separate blocks" '
grep "$(cat 1MB.hash) ->" refs-e.out
'
test_expect_success "output of 'ipfs refs -e' contains all first level links" '
grep "$(cat 1MB.hash) ->" refs-e.out | sed -e '\''s/.* -> //'\'' | sort > refs-s.out &&
ipfs refs "$(cat 1MB.hash)" | sort > refs-one.out &&
test_cmp refs-s.out refs-one.out
'
test_done
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论