@cryptotaxi247 / kubo / commits / e92c4445f

add cmd: clean up default logic of --progress option

License: MIT Signed-off-by: Kevin Atkinson <k@kevina.org>

Kevin Atkinson committed Dec 4, 2016 at 00:03 UTC e92c4445f17fb1d692fced8a59bc4bff881c912d
1 file changed +11 -21
core/commands/add.go
+11 -21
@@ -80,11 +80,14 @@ You can now refer to the added file in a gateway, like so:
80 cmds.BoolOption(rawLeavesOptionName, "Use raw blocks for leaf nodes. (experimental)"),
81 },
82 PreRun: func(req cmds.Request) error {
83 - if quiet, _, _ := req.Option(quietOptionName).Bool(); quiet {
83 + quiet, _, _ := req.Option(quietOptionName).Bool()
84 + silent, _, _ := req.Option(silentOptionName).Bool()
85 +
86 + if quiet || silent {
87 return nil
88 }
89
87 - // ipfs cli progress bar defaults to true
90 + // ipfs cli progress bar defaults to true unless quiet or silent is used
91 _, found, _ := req.Option(progressOptionName).Bool()
92 if !found {
93 req.SetOption(progressOptionName, true)
@@ -245,27 +248,14 @@ You can now refer to the added file in a gateway, like so:
248 return
249 }
250
248 - progress, prgFound, err := req.Option(progressOptionName).Bool()
251 + progress, _, err := req.Option(progressOptionName).Bool()
252 if err != nil {
253 res.SetError(u.ErrCast(), cmds.ErrNormal)
254 return
255 }
256
254 - silent, _, err := req.Option(silentOptionName).Bool()
255 - if err != nil {
256 - res.SetError(u.ErrCast(), cmds.ErrNormal)
257 - return
258 - }
259 -
260 - var showProgressBar bool
261 - if prgFound {
262 - showProgressBar = progress
263 - } else if !quiet && !silent {
264 - showProgressBar = true
265 - }
266 -
257 var bar *pb.ProgressBar
268 - if showProgressBar {
258 + if progress {
259 bar = pb.New64(0).SetUnits(pb.U_BYTES)
260 bar.ManualUpdate = true
261 bar.ShowTimeLeft = false
@@ -292,7 +282,7 @@ You can now refer to the added file in a gateway, like so:
282 }
283 output := out.(*coreunix.AddedObject)
284 if len(output.Hash) > 0 {
295 - if showProgressBar {
285 + if progress {
286 // clear progress bar line before we print "added x" output
287 fmt.Fprintf(res.Stderr(), "\033[2K\r")
288 }
@@ -305,7 +295,7 @@ You can now refer to the added file in a gateway, like so:
295 } else {
296 log.Debugf("add progress: %v %v\n", output.Name, output.Bytes)
297
308 - if !showProgressBar {
298 + if !progress {
299 continue
300 }
301
@@ -321,11 +311,11 @@ You can now refer to the added file in a gateway, like so:
311 totalProgress = bar.Add64(delta)
312 }
313
324 - if showProgressBar {
314 + if progress {
315 bar.Update()
316 }
317 case size := <-sizeChan:
328 - if showProgressBar {
318 + if progress {
319 bar.Total = size
320 bar.ShowPercent = true
321 bar.ShowBar = true