Skip to content

Commit

Permalink
chore: go-multicodec v0.4.1 + helptext fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lidel committed Apr 13, 2022
1 parent e348b59 commit 70c13cf
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
27 changes: 20 additions & 7 deletions core/commands/cid.go
Expand Up @@ -48,7 +48,7 @@ The optional format string is a printf style format string:
` + cidutil.FormatRef,
},
Arguments: []cmds.Argument{
cmds.StringArg("cid", true, true, "Cids to format.").EnableStdin(),
cmds.StringArg("cid", true, true, "CIDs to format.").EnableStdin(),
},
Options: []cmds.Option{
cmds.StringOption(cidFormatOptionName, "Printf style format string.").WithDefault("%s"),
Expand All @@ -65,14 +65,14 @@ The optional format string is a printf style format string:
opts := cidFormatOpts{}

if strings.IndexByte(fmtStr, '%') == -1 {
return fmt.Errorf("invalid format string: %s", fmtStr)
return fmt.Errorf("invalid format string: %q", fmtStr)
}
opts.fmtStr = fmtStr

if codecStr != "" {
codec, ok := cid.Codecs[codecStr]
if !ok {
return fmt.Errorf("unknown IPLD codec: %s", codecStr)
return fmt.Errorf("unknown IPLD codec: %q", codecStr)
}
opts.newCodec = codec
} // otherwise, leave it as 0 (not a valid IPLD codec)
Expand All @@ -82,13 +82,13 @@ The optional format string is a printf style format string:
// noop
case "0":
if opts.newCodec != 0 && opts.newCodec != cid.DagProtobuf {
return fmt.Errorf("cannot convert to CIDv0 with any codec other than DagPB")
return fmt.Errorf("cannot convert to CIDv0 with any codec other than dag-pb")
}
opts.verConv = toCidV0
case "1":
opts.verConv = toCidV1
default:
return fmt.Errorf("invalid cid version: %s", verStr)
return fmt.Errorf("invalid cid version: %q", verStr)
}

if baseStr != "" {
Expand Down Expand Up @@ -125,9 +125,13 @@ type CidFormatRes struct {
var base32Cmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "Convert CIDs to Base32 CID version 1.",
ShortDescription: `
'ipfs cid base32' normalizes passes CIDs to their canonical case-insensitive encoding.
Useful when processing third-party CIDs which could come with arbitrary formats.
`,
},
Arguments: []cmds.Argument{
cmds.StringArg("cid", true, true, "Cids to convert.").EnableStdin(),
cmds.StringArg("cid", true, true, "CIDs to convert.").EnableStdin(),
},
Run: func(req *cmds.Request, resp cmds.ResponseEmitter, env cmds.Environment) error {
opts := cidFormatOpts{
Expand Down Expand Up @@ -234,7 +238,7 @@ func emitCids(req *cmds.Request, resp cmds.ResponseEmitter, opts cidFormatOpts)

func toCidV0(c cid.Cid) (cid.Cid, error) {
if c.Type() != cid.DagProtobuf {
return cid.Cid{}, fmt.Errorf("can't convert non-protobuf nodes to cidv0")
return cid.Cid{}, fmt.Errorf("can't convert non-dag-pb nodes to cidv0")
}
return cid.NewCidV0(c.Hash()), nil
}
Expand All @@ -256,6 +260,9 @@ const (
var basesCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "List available multibase encodings.",
ShortDescription: `
'ipfs cid bases' relies on https://github.com/multiformats/go-multibase
`,
},
Options: []cmds.Option{
cmds.BoolOption(prefixOptionName, "also include the single letter prefixes in addition to the code"),
Expand Down Expand Up @@ -305,6 +312,9 @@ const (
var codecsCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "List available CID codecs.",
ShortDescription: `
'ipfs cid codecs' relies on https://github.com/multiformats/go-multicodec
`,
},
Options: []cmds.Option{
cmds.BoolOption(codecsNumericOptionName, "n", "also include numeric codes"),
Expand Down Expand Up @@ -355,6 +365,9 @@ var codecsCmd = &cmds.Command{
var hashesCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "List available multihashes.",
ShortDescription: `
'ipfs cid hashes' relies on https://github.com/multiformats/go-multihash
`,
},
Options: codecsCmd.Options,
Run: func(req *cmds.Request, resp cmds.ResponseEmitter, env cmds.Environment) error {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -96,7 +96,7 @@ require (
github.com/multiformats/go-multiaddr v0.5.0
github.com/multiformats/go-multiaddr-dns v0.3.1
github.com/multiformats/go-multibase v0.0.3
github.com/multiformats/go-multicodec v0.4.0
github.com/multiformats/go-multicodec v0.4.1
github.com/multiformats/go-multihash v0.1.0
github.com/opentracing/opentracing-go v1.2.0
github.com/pkg/errors v0.9.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Expand Up @@ -1188,8 +1188,8 @@ github.com/multiformats/go-multibase v0.0.3/go.mod h1:5+1R4eQrT3PkYZ24C3W2Ue2tPw
github.com/multiformats/go-multicodec v0.2.0/go.mod h1:/y4YVwkfMyry5kFbMTbLJKErhycTIftytRV+llXdyS4=
github.com/multiformats/go-multicodec v0.3.0/go.mod h1:qGGaQmioCDh+TeFOnxrbU0DaIPw8yFgAZgFG0V7p1qQ=
github.com/multiformats/go-multicodec v0.3.1-0.20210902112759-1539a079fd61/go.mod h1:1Hj/eHRaVWSXiSNNfcEPcwZleTmdNP81xlxDLnWU9GQ=
github.com/multiformats/go-multicodec v0.4.0 h1:fbqb6ky7erjdD+/zaEBJgZWu1i8D6i/wmPywGK7sdow=
github.com/multiformats/go-multicodec v0.4.0/go.mod h1:1Hj/eHRaVWSXiSNNfcEPcwZleTmdNP81xlxDLnWU9GQ=
github.com/multiformats/go-multicodec v0.4.1 h1:BSJbf+zpghcZMZrwTYBGwy0CPcVZGWiC72Cp8bBd4R4=
github.com/multiformats/go-multicodec v0.4.1/go.mod h1:1Hj/eHRaVWSXiSNNfcEPcwZleTmdNP81xlxDLnWU9GQ=
github.com/multiformats/go-multihash v0.0.1/go.mod h1:w/5tugSrLEbWqlcgJabL3oHFKTwfvkofsjW2Qa1ct4U=
github.com/multiformats/go-multihash v0.0.5/go.mod h1:lt/HCbqlQwlPBz7lv0sQCdtfcMtlJvakRUn/0Ual8po=
github.com/multiformats/go-multihash v0.0.8/go.mod h1:YSLudS+Pi8NHE7o6tb3D8vrpKa63epEDmG8nTduyAew=
Expand Down
1 change: 1 addition & 0 deletions test/sharness/t0290-cid.sh
Expand Up @@ -151,6 +151,7 @@ cat <<EOF > supported_codecs_expect
112 dag-pb
113 dag-cbor
120 git-raw
133 dag-jose
297 dag-json
512 json
EOF
Expand Down

0 comments on commit 70c13cf

Please sign in to comment.