Skip to content

Commit 09daf9a

Browse files
committed
fix(cmd): properly pick up --inverse and --cid-file args
1 parent 3a4d09b commit 09daf9a

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

cmd/car/filter.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ func FilterCar(c *cli.Context) error {
2121
var err error
2222
// Get the set of CIDs from stdin.
2323
inStream := os.Stdin
24-
if c.IsSet("cidFile") {
25-
inStream, err = os.Open(c.String("cidFile"))
24+
if c.IsSet("cid-file") {
25+
inStream, err = os.Open(c.String("cid-file"))
2626
if err != nil {
2727
return err
2828
}
@@ -38,7 +38,7 @@ func FilterCar(c *cli.Context) error {
3838
fmt.Printf("filtering to %d cids\n", len(cidMap))
3939
}
4040

41-
return lib.FilterCar(c.Context, c.Args().First(), c.Args().Get(1), cidMap, c.Bool("invert"), c.Int("version"), c.Bool("append"))
41+
return lib.FilterCar(c.Context, c.Args().First(), c.Args().Get(1), cidMap, c.Bool("inverse"), c.Int("version"), c.Bool("append"))
4242
}
4343

4444
func parseCIDS(r io.Reader) (map[cid.Cid]struct{}, error) {

cmd/car/testdata/script/filter.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,24 @@ car filter -append ${INPUTS}/sample-wrapped-v2.car out.car
2121
car list out.car
2222
stdout -count=4 '^bafy'
2323

24+
# --cid-file arg
25+
car filter --cid-file filtersimpleunixfs.txt ${INPUTS}/simple-unixfs.car out.car
26+
stderr 'warning: no roots defined after filtering'
27+
car list out.car
28+
stdout -count=2 '^Qm'
29+
30+
# --cid-file and --inverse args
31+
car filter --cid-file filtersimpleunixfs.txt --inverse ${INPUTS}/simple-unixfs.car out.car
32+
! stderr .
33+
car list out.car
34+
stdout -count=20 '^Qm'
2435

2536
-- filteredcids.txt --
2637
bafy2bzacebohz654namrgmwjjx4qmtwgxixsd7pn4tlanyrc3g3hwj75hlxrw
2738
bafy2bzaceaqtiesyfqd2jibmofz22oolguzf5wscwh73rmeypglfu2xhkptri
2839
bafy2bzacebct3dm7izgyauijzkaf3yd7ylni725k66rq7dfp3jr5ywhpprj3k
2940
-- filteredroot.txt --
3041
bafy2bzaced4ueelaegfs5fqu4tzsh6ywbbpfk3cxppupmxfdhbpbhzawfw5oy
42+
-- filtersimpleunixfs.txt --
43+
QmazwWa2vNLpy6WDBMjx7neWMbmn2oi9LQzCjan4kcGjBX
44+
QmVKt1VVkgfYcbSZqLD9sxZAkDpbH3L7RM6mJ6LHbkj5Bm

0 commit comments

Comments
 (0)