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

change ipfs dag get flag name from format to output-codec #8440

Merged
merged 2 commits into from
Sep 27, 2021
Merged
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
2 changes: 1 addition & 1 deletion core/commands/dag/dag.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ format.
cmds.StringArg("ref", true, false, "The object to get").EnableStdin(),
},
Options: []cmds.Option{
cmds.StringOption("format", "f", "Format that the object will be serialized as.").WithDefault("dag-json"),
cmds.StringOption("output-codec", "Format that the object will be encoded as.").WithDefault("dag-json"),
},
Run: dagGet,
}
Expand Down
10 changes: 5 additions & 5 deletions core/commands/dag/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ func dagGet(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) e
return err
}

format, _ := req.Options["format"].(string)
var fCodec mc.Code
if err := fCodec.Set(format); err != nil {
codecStr, _ := req.Options["output-codec"].(string)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This lack of error handling seems wrong, although this pattern is all over the commands lib usage so likely not too big a problem

var codec mc.Code
if err := codec.Set(codecStr); err != nil {
return err
}

Expand Down Expand Up @@ -54,9 +54,9 @@ func dagGet(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) e
}
}

encoder, err := multicodec.LookupEncoder(uint64(fCodec))
encoder, err := multicodec.LookupEncoder(uint64(codec))
if err != nil {
return fmt.Errorf("invalid encoding: %s - %s", format, err)
return fmt.Errorf("invalid encoding: %s - %s", codec, err)
}

r, w := io.Pipe()
Expand Down
12 changes: 12 additions & 0 deletions test/sharness/t0053-dag.sh
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,18 @@ test_dag_cmd() {
ipfs dag get $IPLDPBHASH >& dag-get-pb
'

test_expect_success "can get dag-pb block transcoded as dag-cbor" '
ipfs dag get --output-codec=dag-cbor $IPLDPBHASH >& dag-get-dagpb-transcoded-to-dagcbor &&
echo "122082a2e4c892e7dcf1d491b30d68aa73ba76bec94f87d4e1a887596ce0730a534a" >sha2_dagpb_to_dagcbor_expected &&
multihash -a=sha2-256 -e=hex dag-get-dagpb-transcoded-to-dagcbor >sha2_dagpb_to_dagcbor_actual &&
test_cmp sha2_dagpb_to_dagcbor_expected sha2_dagpb_to_dagcbor_actual
'

test_expect_success "dag put and dag get transcodings match" '
ROUNDTRIPDAGCBOR=$(ipfs dag put --input-codec=dag-cbor --store-codec=dag-cbor dag-get-dagpb-transcoded-to-dagcbor) &&
test $ROUNDTRIPDAGCBOR = $IPLDCBORHASH
'

# this doesn't tell us if they are correct, we test that better below
test_expect_success "outputs are the same" '
test_cmp dag-get-cbor dag-get-json &&
Expand Down