From 5bfdc2e2b79166f5524d6fdd49158b13393b1cae Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Sun, 30 Nov 2014 13:26:24 +0100 Subject: [PATCH 1/2] Add --quiet option to ipfs add License: MIT Signed-off-by: Christian Couder --- core/commands/add.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/core/commands/add.go b/core/commands/add.go index f09787b9c..92ceeb76d 100644 --- a/core/commands/add.go +++ b/core/commands/add.go @@ -23,6 +23,7 @@ var ErrDepthLimitExceeded = fmt.Errorf("depth limit exceeded") type AddOutput struct { Objects []*Object Names []string + Quiet bool } var addCmd = &cmds.Command{ @@ -41,6 +42,7 @@ remains to be implemented. }, Options: []cmds.Option{ cmds.OptionRecursivePath, // a builtin option that allows recursive paths (-r, --recursive) + cmds.BoolOption("quiet", "q", "Write minimal output"), }, Run: func(req cmds.Request) (interface{}, error) { added := &AddOutput{} @@ -64,6 +66,13 @@ remains to be implemented. } } + quiet, _, err := req.Option("quiet").Bool() + if err != nil { + return nil, err + } + + added.Quiet = quiet + return added, nil }, Marshalers: cmds.MarshalerMap{ @@ -75,7 +84,11 @@ remains to be implemented. var buf bytes.Buffer for i, obj := range val.Objects { - buf.Write([]byte(fmt.Sprintf("added %s %s\n", obj.Hash, val.Names[i]))) + if val.Quiet { + buf.Write([]byte(fmt.Sprintf("%s\n", obj.Hash))) + } else { + buf.Write([]byte(fmt.Sprintf("added %s %s\n", obj.Hash, val.Names[i]))) + } } return buf.Bytes(), nil }, From aca62a420a8d4d38399896bce0ec1457afeec2be Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Sun, 30 Nov 2014 13:29:54 +0100 Subject: [PATCH 2/2] Add sharness test for ipfs add --quiet License: MIT Signed-off-by: Christian Couder --- test/t0040-add-and-cat.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/t0040-add-and-cat.sh b/test/t0040-add-and-cat.sh index 2f20d427e..95ac52f65 100755 --- a/test/t0040-add-and-cat.sh +++ b/test/t0040-add-and-cat.sh @@ -54,6 +54,17 @@ test_expect_success FUSE "cat ipfs/stuff looks good" ' test_cmp expected actual ' +test_expect_success "'ipfs add -q' succeeds" ' + echo "Hello Venus!" >mountdir/venus.txt && + ipfs add -q mountdir/venus.txt >actual +' + +test_expect_success "'ipfs add -q' output looks good" ' + HASH="QmU5kp3BH3B8tnWUU2Pikdb2maksBNkb92FHRr56hyghh4" && + echo "$HASH" >expected && + test_cmp expected actual +' + test_expect_success "go-random is installed" ' type random '