Skip to content

Commit

Permalink
Merge pull request #531 from ipld/rvagg/fixfilter
Browse files Browse the repository at this point in the history
fix(cmd): properly pick up --inverse and --cid-file args
  • Loading branch information
willscott committed Sep 9, 2024
2 parents 3a4d09b + 09daf9a commit 83288ba
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 3 additions & 3 deletions cmd/car/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ func FilterCar(c *cli.Context) error {
var err error
// Get the set of CIDs from stdin.
inStream := os.Stdin
if c.IsSet("cidFile") {
inStream, err = os.Open(c.String("cidFile"))
if c.IsSet("cid-file") {
inStream, err = os.Open(c.String("cid-file"))
if err != nil {
return err
}
Expand All @@ -38,7 +38,7 @@ func FilterCar(c *cli.Context) error {
fmt.Printf("filtering to %d cids\n", len(cidMap))
}

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

func parseCIDS(r io.Reader) (map[cid.Cid]struct{}, error) {
Expand Down
14 changes: 14 additions & 0 deletions cmd/car/testdata/script/filter.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,24 @@ car filter -append ${INPUTS}/sample-wrapped-v2.car out.car
car list out.car
stdout -count=4 '^bafy'

# --cid-file arg
car filter --cid-file filtersimpleunixfs.txt ${INPUTS}/simple-unixfs.car out.car
stderr 'warning: no roots defined after filtering'
car list out.car
stdout -count=2 '^Qm'

# --cid-file and --inverse args
car filter --cid-file filtersimpleunixfs.txt --inverse ${INPUTS}/simple-unixfs.car out.car
! stderr .
car list out.car
stdout -count=20 '^Qm'

-- filteredcids.txt --
bafy2bzacebohz654namrgmwjjx4qmtwgxixsd7pn4tlanyrc3g3hwj75hlxrw
bafy2bzaceaqtiesyfqd2jibmofz22oolguzf5wscwh73rmeypglfu2xhkptri
bafy2bzacebct3dm7izgyauijzkaf3yd7ylni725k66rq7dfp3jr5ywhpprj3k
-- filteredroot.txt --
bafy2bzaced4ueelaegfs5fqu4tzsh6ywbbpfk3cxppupmxfdhbpbhzawfw5oy
-- filtersimpleunixfs.txt --
QmazwWa2vNLpy6WDBMjx7neWMbmn2oi9LQzCjan4kcGjBX
QmVKt1VVkgfYcbSZqLD9sxZAkDpbH3L7RM6mJ6LHbkj5Bm

0 comments on commit 83288ba

Please sign in to comment.