Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate input-enc, add input-format, handle graceful upgrade #8416

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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