From 56a2ae92dc72b514c0a458e433a78d5984d587a0 Mon Sep 17 00:00:00 2001 From: Adin Schmahmann Date: Wed, 15 Sep 2021 15:23:03 -0400 Subject: [PATCH 1/2] change ipfs dag get flag name from format to output-codec --- core/commands/dag/dag.go | 2 +- core/commands/dag/get.go | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/commands/dag/dag.go b/core/commands/dag/dag.go index aa332c43ddd..cbaf7f93fe1 100644 --- a/core/commands/dag/dag.go +++ b/core/commands/dag/dag.go @@ -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, } diff --git a/core/commands/dag/get.go b/core/commands/dag/get.go index bcc7c601709..546ba4e5d19 100644 --- a/core/commands/dag/get.go +++ b/core/commands/dag/get.go @@ -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) + var codec mc.Code + if err := codec.Set(codecStr); err != nil { return err } @@ -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() From d576e53c0454449fb60195ac7be9bf4e7ed39a05 Mon Sep 17 00:00:00 2001 From: Adin Schmahmann Date: Mon, 27 Sep 2021 15:09:04 -0400 Subject: [PATCH 2/2] test: add dag get --ouput-codec test --- test/sharness/t0053-dag.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/sharness/t0053-dag.sh b/test/sharness/t0053-dag.sh index 4f10fd0c428..23666ae672b 100755 --- a/test/sharness/t0053-dag.sh +++ b/test/sharness/t0053-dag.sh @@ -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 &&