diff --git a/core/commands/dag/dag.go b/core/commands/dag/dag.go index 8fabe628948..aa332c43ddd 100644 --- a/core/commands/dag/dag.go +++ b/core/commands/dag/dag.go @@ -84,8 +84,8 @@ into an object of the specified format. cmds.FileArg("object data", true, true, "The object to put").EnableStdin(), }, 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("store-codec", "Codec that the stored object will be encoded with").WithDefault("dag-cbor"), + cmds.StringOption("input-codec", "Codec that the input object is encoded in").WithDefault("dag-json"), cmds.BoolOption("pin", "Pin this object when adding."), cmds.StringOption("hash", "Hash function to use").WithDefault("sha2-256"), }, diff --git a/core/commands/dag/put.go b/core/commands/dag/put.go index f98ab48e464..0bb7fd2ae50 100644 --- a/core/commands/dag/put.go +++ b/core/commands/dag/put.go @@ -31,17 +31,17 @@ func dagPut(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) e return err } - ienc, _ := req.Options["input-enc"].(string) - format, _ := req.Options["format"].(string) + inputCodec, _ := req.Options["input-codec"].(string) + storeCodec, _ := req.Options["store-codec"].(string) hash, _ := req.Options["hash"].(string) dopin, _ := req.Options["pin"].(bool) var icodec mc.Code - if err := icodec.Set(ienc); err != nil { + if err := icodec.Set(inputCodec); err != nil { return err } - var fcodec mc.Code - if err := fcodec.Set(format); err != nil { + var scodec mc.Code + if err := scodec.Set(storeCodec); err != nil { return err } var mhType mc.Code @@ -51,7 +51,7 @@ func dagPut(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) e cidPrefix := cid.Prefix{ Version: 1, - Codec: uint64(fcodec), + Codec: uint64(scodec), MhType: uint64(mhType), MhLength: -1, } @@ -60,7 +60,7 @@ func dagPut(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) e if err != nil { return err } - encoder, err := multicodec.LookupEncoder(uint64(fcodec)) + encoder, err := multicodec.LookupEncoder(uint64(scodec)) if err != nil { return err } diff --git a/test/sharness/t0053-dag.sh b/test/sharness/t0053-dag.sh index b8f8196c137..4f10fd0c428 100755 --- a/test/sharness/t0053-dag.sh +++ b/test/sharness/t0053-dag.sh @@ -45,7 +45,7 @@ test_dag_cmd() { ' test_expect_success "can add an ipld object using dag-json to dag-json" ' - IPLDHASH=$(cat ipld_object | ipfs dag put --input-enc=dag-json -f dag-json) + IPLDHASH=$(cat ipld_object | ipfs dag put --input-codec dag-json --store-codec dag-json) ' test_expect_success "CID looks correct" ' @@ -54,7 +54,7 @@ test_dag_cmd() { ' test_expect_success "can add an ipld object using dag-json to dag-cbor" ' - IPLDHASH=$(cat ipld_object | ipfs dag put --input-enc=dag-json -f dag-cbor) + IPLDHASH=$(cat ipld_object | ipfs dag put --input-codec dag-json --store-codec dag-cbor) ' test_expect_success "CID looks correct" ' @@ -75,7 +75,7 @@ test_dag_cmd() { # (1) dag-cbor input test_expect_success "can add a dag-cbor input block stored as dag-cbor" ' - IPLDCBORHASH=$(cat ipld_object_dagcbor | ipfs dag put --input-enc=dag-cbor -f dag-cbor) + IPLDCBORHASH=$(cat ipld_object_dagcbor | ipfs dag put --input-codec dag-cbor --store-codec dag-cbor) ' test_expect_success "dag-cbor CID looks correct" ' @@ -84,7 +84,7 @@ test_dag_cmd() { ' test_expect_success "can add a dag-cbor input block stored as dag-pb" ' - IPLDPBHASH=$(cat ipld_object_dagcbor | ipfs dag put --input-enc=dag-cbor -f dag-pb) + IPLDPBHASH=$(cat ipld_object_dagcbor | ipfs dag put --input-codec dag-cbor --store-codec dag-pb) ' test_expect_success "dag-pb CID looks correct" ' @@ -93,7 +93,7 @@ test_dag_cmd() { ' test_expect_success "can add a dag-cbor input block stored as dag-json" ' - IPLDJSONHASH=$(cat ipld_object_dagcbor | ipfs dag put --input-enc=dag-cbor -f dag-json) + IPLDJSONHASH=$(cat ipld_object_dagcbor | ipfs dag put --input-codec dag-cbor --store-codec dag-json) ' test_expect_success "dag-json CID looks correct" ' @@ -104,7 +104,7 @@ test_dag_cmd() { # (2) dag-json input test_expect_success "can add a dag-json input block stored as dag-cbor" ' - IPLDCBORHASH=$(cat ipld_object_dagjson | ipfs dag put --input-enc=dag-json -f dag-cbor) + IPLDCBORHASH=$(cat ipld_object_dagjson | ipfs dag put --input-codec dag-json --store-codec dag-cbor) ' test_expect_success "dag-cbor CID looks correct" ' @@ -113,7 +113,7 @@ test_dag_cmd() { ' test_expect_success "can add a dag-json input block stored as dag-pb" ' - IPLDPBHASH=$(cat ipld_object_dagjson | ipfs dag put --input-enc=dag-json -f dag-pb) + IPLDPBHASH=$(cat ipld_object_dagjson | ipfs dag put --input-codec dag-json --store-codec dag-pb) ' test_expect_success "dag-pb CID looks correct" ' @@ -122,7 +122,7 @@ test_dag_cmd() { ' test_expect_success "can add a dag-json input block stored as dag-json" ' - IPLDJSONHASH=$(cat ipld_object_dagjson | ipfs dag put --input-enc=dag-json -f dag-json) + IPLDJSONHASH=$(cat ipld_object_dagjson | ipfs dag put --input-codec dag-json --store-codec dag-json) ' test_expect_success "dag-json CID looks correct" ' @@ -133,7 +133,7 @@ test_dag_cmd() { # (3) dag-pb input test_expect_success "can add a dag-pb input block stored as dag-cbor" ' - IPLDCBORHASH=$(cat ipld_object_dagpb | ipfs dag put --input-enc=dag-pb -f dag-cbor) + IPLDCBORHASH=$(cat ipld_object_dagpb | ipfs dag put --input-codec dag-pb --store-codec dag-cbor) ' test_expect_success "dag-cbor CID looks correct" ' @@ -142,7 +142,7 @@ test_dag_cmd() { ' test_expect_success "can add a dag-pb input block stored as dag-pb" ' - IPLDPBHASH=$(cat ipld_object_dagpb | ipfs dag put --input-enc=dag-pb -f dag-pb) + IPLDPBHASH=$(cat ipld_object_dagpb | ipfs dag put --input-codec dag-pb --store-codec dag-pb) ' test_expect_success "dag-pb CID looks correct" ' @@ -151,7 +151,7 @@ test_dag_cmd() { ' test_expect_success "can add a dag-pb input block stored as dag-json" ' - IPLDJSONHASH=$(cat ipld_object_dagpb | ipfs dag put --input-enc=dag-pb -f dag-json) + IPLDJSONHASH=$(cat ipld_object_dagpb | ipfs dag put --input-codec dag-pb --store-codec dag-json) ' test_expect_success "dag-json CID looks correct" ' @@ -245,7 +245,7 @@ test_dag_cmd() { ' test_expect_success "retrieved object hashes back correctly" ' - IPLDHASH2=$(cat ipld_obj_out | ipfs dag put --input-enc=dag-json -f dag-cbor) && + IPLDHASH2=$(cat ipld_obj_out | ipfs dag put --input-codec dag-json --store-codec dag-cbor) && test "$IPLDHASH" = "$IPLDHASH2" ' @@ -272,7 +272,7 @@ test_dag_cmd() { ' test_expect_success "non-canonical dag-cbor input is normalized" ' - HASH=$(cat ../t0053-dag-data/non-canon.cbor | ipfs dag put --format=dag-cbor --input-enc=dag-cbor) && + HASH=$(cat ../t0053-dag-data/non-canon.cbor | ipfs dag put --store-codec dag-cbor --input-codec dag-cbor) && test $HASH = "bafyreiawx7ona7oa2ptcoh6vwq4q6bmd7x2ibtkykld327bgb7t73ayrqm" || test_fsh echo $HASH ' @@ -283,7 +283,7 @@ test_dag_cmd() { ' test_expect_success "add an ipld with pin" ' - PINHASH=$(printf {\"foo\":\"bar\"} | ipfs dag put --input-enc=dag-json --pin=true) + PINHASH=$(printf {\"foo\":\"bar\"} | ipfs dag put --input-codec dag-json --pin=true) ' test_expect_success "after gc, objects still accessible" ' @@ -307,7 +307,7 @@ test_dag_cmd() { test_expect_success "dag put with json dag-pb works" ' ipfs dag get $HASH > pbjson && - cat pbjson | ipfs dag put --format=dag-pb --input-enc=dag-json > dag_put_out + cat pbjson | ipfs dag put --store-codec=dag-pb --input-codec=dag-json > dag_put_out ' test_expect_success "dag put with dag-pb works output looks good" ' @@ -317,7 +317,7 @@ test_dag_cmd() { test_expect_success "dag put with raw dag-pb works" ' ipfs block get $HASH > pbraw && - cat pbraw | ipfs dag put --format=dag-pb --input-enc=dag-pb > dag_put_out + cat pbraw | ipfs dag put --store-codec=dag-pb --input-codec=dag-pb > dag_put_out ' test_expect_success "dag put with dag-pb works output looks good" ' @@ -327,7 +327,7 @@ test_dag_cmd() { test_expect_success "dag put with raw node works" ' echo "foo bar" > raw_node_in && - HASH=$(ipfs dag put --format=raw --input-enc=raw -- raw_node_in) && + HASH=$(ipfs dag put --store-codec=raw --input-codec=raw -- raw_node_in) && ipfs block get "$HASH" > raw_node_out && test_cmp raw_node_in raw_node_out' diff --git a/test/sharness/t0055-dag-put-json-new-line.sh b/test/sharness/t0055-dag-put-json-new-line.sh index d69806760cd..1fde33ab61d 100755 --- a/test/sharness/t0055-dag-put-json-new-line.sh +++ b/test/sharness/t0055-dag-put-json-new-line.sh @@ -14,8 +14,8 @@ test_expect_success 'create test JSON files' ' ' test_expect_success 'puts as CBOR work' ' - GOT_HASH_WITHOUT_NEWLINE="$(cat without_newline.json | ipfs dag put -f dag-cbor)" - GOT_HASH_WITH_NEWLINE="$(cat with_newline.json | ipfs dag put -f dag-cbor)" + GOT_HASH_WITHOUT_NEWLINE="$(cat without_newline.json | ipfs dag put --store-codec dag-cbor)" + GOT_HASH_WITH_NEWLINE="$(cat with_newline.json | ipfs dag put --store-codec dag-cbor)" ' test_expect_success 'put hashes with or without newline are equal' ' diff --git a/test/sharness/t0280-plugin-git.sh b/test/sharness/t0280-plugin-git.sh index 4e035254924..c3ffc882dde 100755 --- a/test/sharness/t0280-plugin-git.sh +++ b/test/sharness/t0280-plugin-git.sh @@ -17,7 +17,7 @@ test_expect_success "prepare test data" ' test_dag_git() { test_expect_success "add objects via dag put" ' - find objects -type f -exec ipfs dag put --format=git-raw --input-enc=0x300078 --hash=sha1 {} \; -exec echo -n \; > hashes + find objects -type f -exec ipfs dag put --store-codec=git-raw --input-codec=0x300078 --hash=sha1 {} \; -exec echo -n \; > hashes ' test_expect_success "successfully get added objects" '