Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cmd): properly pick up --inverse and --cid-file args #531

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading