@cryptotaxi247 / kubo / commits / 03dd66943

Refactor progress and showProgressBar

License: MIT Signed-off-by: Richard Littauer <richard.littauer@gmail.com>

Richard Littauer committed May 21, 2016 at 12:37 UTC 03dd669430474ae8396e6fe9eba9e47f01c0ed75
2 files changed +12 -11
core/commands/add.go
+7 -8
@@ -222,14 +222,13 @@ You can now refer to the added file in a gateway, like so:
222 return
223 }
224
225 - var showProgressBar bool
226 - if !progress && !quiet && !silent {
227 - showProgressBar = true
225 + if !quiet && !silent {
226 + progress = true
227 }
228
229 var bar *pb.ProgressBar
230 var terminalWidth int
232 - if showProgressBar {
231 + if progress {
232 bar = pb.New64(0).SetUnits(pb.U_BYTES)
233 bar.ManualUpdate = true
234 bar.Start()
@@ -264,7 +263,7 @@ You can now refer to the added file in a gateway, like so:
263 }
264 output := out.(*coreunix.AddedObject)
265 if len(output.Hash) > 0 {
267 - if showProgressBar {
266 + if progress {
267 // clear progress bar line before we print "added x" output
268 fmt.Fprintf(res.Stderr(), "\033[2K\r")
269 }
@@ -277,7 +276,7 @@ You can now refer to the added file in a gateway, like so:
276 } else {
277 log.Debugf("add progress: %v %v\n", output.Name, output.Bytes)
278
280 - if !showProgressBar {
279 + if !progress {
280 continue
281 }
282
@@ -293,11 +292,11 @@ You can now refer to the added file in a gateway, like so:
292 totalProgress = bar.Add64(delta)
293 }
294
296 - if showProgressBar {
295 + if progress {
296 bar.Update()
297 }
298 case size := <-sizeChan:
300 - if showProgressBar {
299 + if progress {
300 bar.Total = size
301 bar.ShowPercent = true
302 bar.ShowBar = true
test/sharness/t0040-add-and-cat.sh
+5 -3
@@ -11,9 +11,11 @@ test_description="Test add and cat commands"
11 client_err_add() {
12 printf "$@\n\n"
13 echo 'USAGE
14 - ipfs add <path>... - Add a file or directory to ipfs.
14 + ipfs add <path>... - Add a file to ipfs.
15
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.
19
20 Use '"'"'ipfs add --help'"'"' for more information about this command.
21 '
@@ -360,7 +362,7 @@ test_add_cat_5MB
362
363 test_add_cat_expensive
364
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:"
366
367 test_kill_ipfs_daemon
368