Skip to content

Commit 8d9820a

Browse files
committed
Refactor progress and showProgressBar
License: MIT Signed-off-by: Richard Littauer <[email protected]>
1 parent 6f796dc commit 8d9820a

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

core/commands/add.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -222,14 +222,13 @@ You can now refer to the added file in a gateway, like so:
222222
return
223223
}
224224

225-
var showProgressBar bool
226-
if !progress && !quiet && !silent {
227-
showProgressBar = true
225+
if !quiet && !silent {
226+
progress = true
228227
}
229228

230229
var bar *pb.ProgressBar
231230
var terminalWidth int
232-
if showProgressBar {
231+
if progress {
233232
bar = pb.New64(0).SetUnits(pb.U_BYTES)
234233
bar.ManualUpdate = true
235234
bar.Start()
@@ -264,7 +263,7 @@ You can now refer to the added file in a gateway, like so:
264263
}
265264
output := out.(*coreunix.AddedObject)
266265
if len(output.Hash) > 0 {
267-
if showProgressBar {
266+
if progress {
268267
// clear progress bar line before we print "added x" output
269268
fmt.Fprintf(res.Stderr(), "\033[2K\r")
270269
}
@@ -277,7 +276,7 @@ You can now refer to the added file in a gateway, like so:
277276
} else {
278277
log.Debugf("add progress: %v %v\n", output.Name, output.Bytes)
279278

280-
if !showProgressBar {
279+
if !progress {
281280
continue
282281
}
283282

@@ -293,11 +292,11 @@ You can now refer to the added file in a gateway, like so:
293292
totalProgress = bar.Add64(delta)
294293
}
295294

296-
if showProgressBar {
295+
if progress {
297296
bar.Update()
298297
}
299298
case size := <-sizeChan:
300-
if showProgressBar {
299+
if progress {
301300
bar.Total = size
302301
bar.ShowPercent = true
303302
bar.ShowBar = true

test/sharness/t0040-add-and-cat.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ test_add_cat_5MB
360360

361361
test_add_cat_expensive
362362

363-
test_add_named_pipe " Post http://$API_ADDR/api/v0/add?encoding=json&progress=true&r=true&stream-channels=true:"
363+
test_add_named_pipe " Post http://$API_ADDR/api/v0/add?encoding=json&r=true&stream-channels=true:"
364364

365365
test_kill_ipfs_daemon
366366

0 commit comments

Comments
 (0)