Skip to content

Commit 5bfdc2e

Browse files
committed
Add --quiet option to ipfs add
License: MIT Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
1 parent ff23d2d commit 5bfdc2e

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

core/commands/add.go

+14-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ var ErrDepthLimitExceeded = fmt.Errorf("depth limit exceeded")
2323
type AddOutput struct {
2424
Objects []*Object
2525
Names []string
26+
Quiet bool
2627
}
2728

2829
var addCmd = &cmds.Command{
@@ -41,6 +42,7 @@ remains to be implemented.
4142
},
4243
Options: []cmds.Option{
4344
cmds.OptionRecursivePath, // a builtin option that allows recursive paths (-r, --recursive)
45+
cmds.BoolOption("quiet", "q", "Write minimal output"),
4446
},
4547
Run: func(req cmds.Request) (interface{}, error) {
4648
added := &AddOutput{}
@@ -64,6 +66,13 @@ remains to be implemented.
6466
}
6567
}
6668

69+
quiet, _, err := req.Option("quiet").Bool()
70+
if err != nil {
71+
return nil, err
72+
}
73+
74+
added.Quiet = quiet
75+
6776
return added, nil
6877
},
6978
Marshalers: cmds.MarshalerMap{
@@ -75,7 +84,11 @@ remains to be implemented.
7584

7685
var buf bytes.Buffer
7786
for i, obj := range val.Objects {
78-
buf.Write([]byte(fmt.Sprintf("added %s %s\n", obj.Hash, val.Names[i])))
87+
if val.Quiet {
88+
buf.Write([]byte(fmt.Sprintf("%s\n", obj.Hash)))
89+
} else {
90+
buf.Write([]byte(fmt.Sprintf("added %s %s\n", obj.Hash, val.Names[i])))
91+
}
7992
}
8093
return buf.Bytes(), nil
8194
},

0 commit comments

Comments
 (0)