Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement the -q or --quiet flag to add with minimal output #372

Merged
merged 2 commits into from
Dec 5, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion core/commands/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var ErrDepthLimitExceeded = fmt.Errorf("depth limit exceeded")
type AddOutput struct {
Objects []*Object
Names []string
Quiet bool
}

var addCmd = &cmds.Command{
Expand All @@ -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{}
Expand All @@ -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{
Expand All @@ -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
},
Expand Down
11 changes: 11 additions & 0 deletions test/t0040-add-and-cat.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
'
Expand Down