diff --git a/core/commands/add.go b/core/commands/add.go index f09787b9c73..92ceeb76d4d 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 }, diff --git a/test/t0040-add-and-cat.sh b/test/t0040-add-and-cat.sh index 2f20d427e62..95ac52f6589 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 '