Skip to content

Commit e92c444

Browse files
committed
add cmd: clean up default logic of --progress option
License: MIT Signed-off-by: Kevin Atkinson <[email protected]>
1 parent 0b8e032 commit e92c444

File tree

1 file changed

+11
-21
lines changed

1 file changed

+11
-21
lines changed

core/commands/add.go

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,14 @@ You can now refer to the added file in a gateway, like so:
8080
cmds.BoolOption(rawLeavesOptionName, "Use raw blocks for leaf nodes. (experimental)"),
8181
},
8282
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 {
8487
return nil
8588
}
8689

87-
// ipfs cli progress bar defaults to true
90+
// ipfs cli progress bar defaults to true unless quiet or silent is used
8891
_, found, _ := req.Option(progressOptionName).Bool()
8992
if !found {
9093
req.SetOption(progressOptionName, true)
@@ -245,27 +248,14 @@ You can now refer to the added file in a gateway, like so:
245248
return
246249
}
247250

248-
progress, prgFound, err := req.Option(progressOptionName).Bool()
251+
progress, _, err := req.Option(progressOptionName).Bool()
249252
if err != nil {
250253
res.SetError(u.ErrCast(), cmds.ErrNormal)
251254
return
252255
}
253256

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-
267257
var bar *pb.ProgressBar
268-
if showProgressBar {
258+
if progress {
269259
bar = pb.New64(0).SetUnits(pb.U_BYTES)
270260
bar.ManualUpdate = true
271261
bar.ShowTimeLeft = false
@@ -292,7 +282,7 @@ You can now refer to the added file in a gateway, like so:
292282
}
293283
output := out.(*coreunix.AddedObject)
294284
if len(output.Hash) > 0 {
295-
if showProgressBar {
285+
if progress {
296286
// clear progress bar line before we print "added x" output
297287
fmt.Fprintf(res.Stderr(), "\033[2K\r")
298288
}
@@ -305,7 +295,7 @@ You can now refer to the added file in a gateway, like so:
305295
} else {
306296
log.Debugf("add progress: %v %v\n", output.Name, output.Bytes)
307297

308-
if !showProgressBar {
298+
if !progress {
309299
continue
310300
}
311301

@@ -321,11 +311,11 @@ You can now refer to the added file in a gateway, like so:
321311
totalProgress = bar.Add64(delta)
322312
}
323313

324-
if showProgressBar {
314+
if progress {
325315
bar.Update()
326316
}
327317
case size := <-sizeChan:
328-
if showProgressBar {
318+
if progress {
329319
bar.Total = size
330320
bar.ShowPercent = true
331321
bar.ShowBar = true

0 commit comments

Comments
 (0)