Skip to content

Commit

Permalink
Merge pull request #8440 from ipfs/feat/change-dag-get-flag-name
Browse files Browse the repository at this point in the history
change ipfs dag get flag name from format to output-codec
  • Loading branch information
aschmahmann authored Sep 27, 2021
2 parents ea45dc8 + d576e53 commit 51893f6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
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)
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

0 comments on commit 51893f6

Please sign in to comment.