From 09daf9a6b77f9417650439819cc7cce9c5371e02 Mon Sep 17 00:00:00 2001 From: Rod Vagg Date: Mon, 9 Sep 2024 20:25:30 +1000 Subject: [PATCH] fix(cmd): properly pick up --inverse and --cid-file args --- cmd/car/filter.go | 6 +++--- cmd/car/testdata/script/filter.txt | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/cmd/car/filter.go b/cmd/car/filter.go index d4c6c1d5..bbc2edb6 100644 --- a/cmd/car/filter.go +++ b/cmd/car/filter.go @@ -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 } @@ -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) { diff --git a/cmd/car/testdata/script/filter.txt b/cmd/car/testdata/script/filter.txt index 0c0b12de..6e22d44f 100644 --- a/cmd/car/testdata/script/filter.txt +++ b/cmd/car/testdata/script/filter.txt @@ -21,6 +21,17 @@ 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 @@ -28,3 +39,6 @@ bafy2bzaceaqtiesyfqd2jibmofz22oolguzf5wscwh73rmeypglfu2xhkptri bafy2bzacebct3dm7izgyauijzkaf3yd7ylni725k66rq7dfp3jr5ywhpprj3k -- filteredroot.txt -- bafy2bzaced4ueelaegfs5fqu4tzsh6ywbbpfk3cxppupmxfdhbpbhzawfw5oy +-- filtersimpleunixfs.txt -- +QmazwWa2vNLpy6WDBMjx7neWMbmn2oi9LQzCjan4kcGjBX +QmVKt1VVkgfYcbSZqLD9sxZAkDpbH3L7RM6mJ6LHbkj5Bm \ No newline at end of file