1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-07-01 10:49:24 +08:00

Merge pull request #372 from chriscool/add_quiet_flag

Implement the -q or --quiet flag to add with minimal output
This commit is contained in:
Juan Batiz-Benet
2014-12-05 15:45:49 -05:00
2 changed files with 25 additions and 1 deletions

View File

@ -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
},

View File

@ -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
'