@cryptotaxi247 / kubo / commits / 697afddbc

object: --quiet flag to put

License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>

Łukasz Magiera committed Nov 21, 2017 at 19:39 UTC 697afddbcc8caf7534cb6c1abc63e8be6db0b11d
2 files changed +20 -2
core/commands/object/object.go
+10 -2
@@ -19,10 +19,10 @@ import (
19 path "github.com/ipfs/go-ipfs/path"
20 pin "github.com/ipfs/go-ipfs/pin"
21 ft "github.com/ipfs/go-ipfs/unixfs"
22 - cmdkit "gx/ipfs/QmUyfy4QSr3NXym4etEiRyxBLqqAeKHJuRdi8AACxg63fZ/go-ipfs-cmdkit"
22
23 cid "gx/ipfs/QmNp85zy9RLrQ5oQD4hPyS39ezrrXpcaa7R4Y9kxdWQLLQ/go-cid"
24 node "gx/ipfs/QmPN7cwmpcc4DWXb4KTB9dNAJgjuPY69h3npsMfhRrQL9c/go-ipld-format"
25 + cmdkit "gx/ipfs/QmUyfy4QSr3NXym4etEiRyxBLqqAeKHJuRdi8AACxg63fZ/go-ipfs-cmdkit"
26 )
27
28 // ErrObjectTooLarge is returned when too much data was read from stdin. current limit 2m
@@ -385,6 +385,7 @@ And then run:
385 cmdkit.StringOption("inputenc", "Encoding type of input data. One of: {\"protobuf\", \"json\"}.").WithDefault("json"),
386 cmdkit.StringOption("datafieldenc", "Encoding type of the data field, either \"text\" or \"base64\".").WithDefault("text"),
387 cmdkit.BoolOption("pin", "Pin this object when adding."),
388 + cmdkit.BoolOption("quiet", "q", "Write minimal output."),
389 },
390 Run: func(req cmds.Request, res cmds.Response) {
391 n, err := req.InvocContext().GetNode()
@@ -444,6 +445,8 @@ And then run:
445 },
446 Marshalers: cmds.MarshalerMap{
447 cmds.Text: func(res cmds.Response) (io.Reader, error) {
448 + quiet, _, _ := res.Request().Option("quiet").Bool()
449 +
450 v, err := unwrapOutput(res.Output())
451 if err != nil {
452 return nil, err
@@ -453,7 +456,12 @@ And then run:
456 return nil, e.TypeErr(obj, v)
457 }
458
456 - return strings.NewReader("added " + obj.Hash + "\n"), nil
459 + out := obj.Hash + "\n"
460 + if !quiet {
461 + out = "added " + out
462 + }
463 +
464 + return strings.NewReader(out), nil
465 },
466 },
467 Type: Object{},
test/sharness/t0051-object.sh
+10
@@ -70,6 +70,16 @@ test_object_cmd() {
70 test_cmp expected_putOut actual_putOut
71 '
72
73 + test_expect_success "'ipfs object put --quiet file.json' succeeds" '
74 + ipfs object put --quiet ../t0051-object-data/testPut.json > actual_putOut
75 + '
76 +
77 + test_expect_success "'ipfs object put --quiet file.json' output looks good" '
78 + HASH="QmUTSAdDi2xsNkDtLqjFgQDMEn5di3Ab9eqbrt4gaiNbUD" &&
79 + printf "$HASH\n" > expected_putOut &&
80 + test_cmp expected_putOut actual_putOut
81 + '
82 +
83 test_expect_success "'ipfs object put file.xml' succeeds" '
84 ipfs object put ../t0051-object-data/testPut.xml --inputenc=xml > actual_putOut
85 '