shed: Support raw encoding in cid id

This commit is contained in:
Łukasz Magiera 2021-08-10 16:47:55 +02:00
parent 5bdc1862d9
commit 69204eea04

View File

@ -27,6 +27,7 @@ var cidIdCmd = &cli.Command{
Flags: []cli.Flag{ Flags: []cli.Flag{
&cli.StringFlag{ &cli.StringFlag{
Name: "encoding", Name: "encoding",
Aliases: []string{"e"},
Value: "base64", Value: "base64",
Usage: "specify input encoding to parse", Usage: "specify input encoding to parse",
}, },
@ -49,12 +50,14 @@ var cidIdCmd = &cli.Command{
return xerrors.Errorf("decoding base64 value: %w", err) return xerrors.Errorf("decoding base64 value: %w", err)
} }
dec = data dec = data
case "hex": case "hex", "x":
data, err := hex.DecodeString(cctx.Args().First()) data, err := hex.DecodeString(cctx.Args().First())
if err != nil { if err != nil {
return xerrors.Errorf("decoding hex value: %w", err) return xerrors.Errorf("decoding hex value: %w", err)
} }
dec = data dec = data
case "raw", "r":
dec = []byte(cctx.Args().First())
default: default:
return xerrors.Errorf("unrecognized encoding: %s", cctx.String("encoding")) return xerrors.Errorf("unrecognized encoding: %s", cctx.String("encoding"))
} }