diff --git a/cmd/car/car.go b/cmd/car/car.go index 76a1ed49..850673c6 100644 --- a/cmd/car/car.go +++ b/cmd/car/car.go @@ -91,9 +91,10 @@ func main1() int { Usage: "The type of index to write", Value: multicodec.CarMultihashIndexSorted.String(), }, - &cli.BoolFlag{ - Name: "v1", - Usage: "Write out only the carV1 file. Implies codec of 'none'", + &cli.IntFlag{ + Name: "version", + Value: 2, + Usage: "Write output as a v1 or v2 format car", }, }, }, diff --git a/cmd/car/index.go b/cmd/car/index.go index ac368886..153c0b7c 100644 --- a/cmd/car/index.go +++ b/cmd/car/index.go @@ -23,9 +23,9 @@ func IndexCar(c *cli.Context) error { } defer r.Close() - if c.Bool("v1") { + if c.Int("version") == 1 { if c.IsSet("codec") && c.String("codec") != "none" { - return fmt.Errorf("only supported codec for a v1 car is 'none'") + return fmt.Errorf("'none' is the only supported codec for a v1 car") } outStream := os.Stdout if c.Args().Len() >= 2 { @@ -40,6 +40,10 @@ func IndexCar(c *cli.Context) error { return err } + if c.Int("version") != 2 { + return fmt.Errorf("invalid CAR version %d", c.Int("version")) + } + var idx index.Index if c.String("codec") != "none" { var mc multicodec.Code