@cryptotaxi247 / kubo / commits / 5bfdc2e2b

Add --quiet option to ipfs add

License: MIT Signed-off-by: Christian Couder <chriscool@tuxfamily.org>

Christian Couder committed Nov 30, 2014 at 13:26 UTC 5bfdc2e2b79166f5524d6fdd49158b13393b1cae
1 file changed +14 -1
core/commands/add.go
+14 -1
@@ -23,6 +23,7 @@ var ErrDepthLimitExceeded = fmt.Errorf("depth limit exceeded")
23 type AddOutput struct {
24 Objects []*Object
25 Names []string
26 + Quiet bool
27 }
28
29 var addCmd = &cmds.Command{
@@ -41,6 +42,7 @@ remains to be implemented.
42 },
43 Options: []cmds.Option{
44 cmds.OptionRecursivePath, // a builtin option that allows recursive paths (-r, --recursive)
45 + cmds.BoolOption("quiet", "q", "Write minimal output"),
46 },
47 Run: func(req cmds.Request) (interface{}, error) {
48 added := &AddOutput{}
@@ -64,6 +66,13 @@ remains to be implemented.
66 }
67 }
68
69 + quiet, _, err := req.Option("quiet").Bool()
70 + if err != nil {
71 + return nil, err
72 + }
73 +
74 + added.Quiet = quiet
75 +
76 return added, nil
77 },
78 Marshalers: cmds.MarshalerMap{
@@ -75,7 +84,11 @@ remains to be implemented.
84
85 var buf bytes.Buffer
86 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 + }
92 }
93 return buf.Bytes(), nil
94 },