Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 636c45d

Browse files
committedJan 22, 2016
core/commands/pin: implement --count for 'ipfs pin ls'
License: MIT Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
1 parent 9c1375f commit 636c45d

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed
 

‎core/commands/pin.go

+14-5
Original file line numberDiff line numberDiff line change
@@ -248,16 +248,25 @@ Example:
248248
return nil, err
249249
}
250250

251+
count, _, err := res.Request().Option("count").Bool()
252+
if err != nil {
253+
return nil, err
254+
}
255+
251256
keys, ok := res.Output().(*RefKeyList)
252257
if !ok {
253258
return nil, u.ErrCast()
254259
}
255260
out := new(bytes.Buffer)
256-
for k, v := range keys.Keys {
257-
if quiet {
258-
fmt.Fprintf(out, "%s\n", k)
259-
} else {
260-
fmt.Fprintf(out, "%s %s\n", k, v.Type)
261+
if count {
262+
fmt.Fprintf(out, "%d\n", len(keys.Keys))
263+
} else {
264+
for k, v := range keys.Keys {
265+
if quiet {
266+
fmt.Fprintf(out, "%s\n", k)
267+
} else {
268+
fmt.Fprintf(out, "%s %s\n", k, v.Type)
269+
}
261270
}
262271
}
263272
return out, nil

‎test/sharness/t0081-repo-pinning.sh

+12-1
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,22 @@ test_expect_success "ipfs object links $HASH_DIR1 works" '
119119
ipfs object links $HASH_DIR1 > DIR1_objlink
120120
'
121121

122-
123122
test_expect_success "added dir was pinned recursively" '
124123
test_pin_flag $HASH_DIR1 recursive true
125124
'
126125

126+
test_expect_success "'ipfs pin ls --count' works" '
127+
ipfs pin ls --count --type=all >actual_all &&
128+
ipfs pin ls --count --type=recursive >actual_recursive
129+
'
130+
131+
test_expect_success "'ipfs pin ls --count' output looks good" '
132+
echo "18" >expected_all &&
133+
echo "3" >expected_recursive &&
134+
test_cmp expected_all actual_all &&
135+
test_cmp expected_recursive actual_recursive
136+
'
137+
127138
test_expect_success "rest were pinned indirectly" '
128139
test_pin_flag "$HASH_FILE6" indirect true
129140
test_pin_flag "$HASH_FILE5" indirect true

0 commit comments

Comments
 (0)
Please sign in to comment.