Skip to content

Commit

Permalink
Deprecate input-enc, add input-format, handle graceful upgrade
Browse files Browse the repository at this point in the history
Ref: #8415
  • Loading branch information
rvagg committed Sep 8, 2021
1 parent 65d570c commit 20e65e7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
3 changes: 2 additions & 1 deletion core/commands/dag/dag.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ into an object of the specified format.
},
Options: []cmds.Option{
cmds.StringOption("format", "f", "Format that the object will be added as.").WithDefault("dag-cbor"),
cmds.StringOption("input-enc", "Format that the input object will be.").WithDefault("dag-json"),
cmds.StringOption("input-format", "Format that the input object will be."),
cmds.StringOption("input-enc", "Format that the input object will be (DEPRECATED)."),
cmds.BoolOption("pin", "Pin this object when adding."),
cmds.StringOption("hash", "Hash function to use").WithDefault("sha2-256"),
},
Expand Down
17 changes: 16 additions & 1 deletion core/commands/dag/put.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,27 @@ func dagPut(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) e
}

ienc, _ := req.Options["input-enc"].(string)
iformat, _ := req.Options["input-format"].(string)
format, _ := req.Options["format"].(string)
hash, _ := req.Options["hash"].(string)
dopin, _ := req.Options["pin"].(bool)

// deal with legacy --input-enc option, see dagtransl.go, as well as setting
// the default value to dag-json if nothing else is specified
if iformat == "" {
switch ienc {
case "raw", "cbor", "protobuf":
// decode the raw bytes as the `--format` requested
iformat = format
case "json", "":
iformat = "dag-json"
default:
iformat = ienc
}
} // else `--input-format` overrides `--input-enc`

var icodec mc.Code
if err := icodec.Set(ienc); err != nil {
if err := icodec.Set(iformat); err != nil {
return err
}
var fcodec mc.Code
Expand Down

0 comments on commit 20e65e7

Please sign in to comment.