Skip to content

Commit 03dd669

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

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
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: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ test_description="Test add and cat commands"
1111
client_err_add() {
1212
printf "$@\n\n"
1313
echo 'USAGE
14-
ipfs add <path>... - Add a file or directory to ipfs.
14+
ipfs add <path>... - Add a file to ipfs.
1515
16-
Adds contents of <path> to ipfs. Use -r to add directories (recursively).
16+
Adds contents of <path> to ipfs. Use -r to add directories.
17+
Note that directories are added recursively, to form the ipfs
18+
MerkleDAG.
1719
1820
Use '"'"'ipfs add --help'"'"' for more information about this command.
1921
'
@@ -360,7 +362,7 @@ test_add_cat_5MB
360362

361363
test_add_cat_expensive
362364

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

365367
test_kill_ipfs_daemon
366368

0 commit comments

Comments
 (0)