@@ -36,11 +36,9 @@ const (
36
36
37
37
var AddCmd = & cmds.Command {
38
38
Helptext : cmds.HelpText {
39
- Tagline : "Add a file to ipfs." ,
39
+ Tagline : "Add a file or directory to ipfs." ,
40
40
ShortDescription : `
41
- Adds contents of <path> to ipfs. Use -r to add directories.
42
- Note that directories are added recursively, to form the ipfs
43
- MerkleDAG.
41
+ Adds contents of <path> to ipfs. Use -r to add directories (recursively).
44
42
` ,
45
43
LongDescription : `
46
44
Adds contents of <path> to ipfs. Use -r to add directories.
@@ -69,26 +67,29 @@ You can now refer to the added file in a gateway, like so:
69
67
},
70
68
Options : []cmds.Option {
71
69
cmds .OptionRecursivePath , // a builtin option that allows recursive paths (-r, --recursive)
72
- cmds .BoolOption (quietOptionName , "q" , "Write minimal output." ). Default ( false ) ,
73
- cmds .BoolOption (silentOptionName , "Write no output." ). Default ( false ) ,
70
+ cmds .BoolOption (quietOptionName , "q" , "Write minimal output." ),
71
+ cmds .BoolOption (silentOptionName , "Write no output." ),
74
72
cmds .BoolOption (progressOptionName , "p" , "Stream progress data." ),
75
- cmds .BoolOption (trickleOptionName , "t" , "Use trickle-dag format for dag generation." ). Default ( false ) ,
76
- cmds .BoolOption (onlyHashOptionName , "n" , "Only chunk and hash - do not write to disk." ). Default ( false ) ,
77
- cmds .BoolOption (wrapOptionName , "w" , "Wrap files with a directory object." ). Default ( false ) ,
78
- cmds .BoolOption (hiddenOptionName , "H" , "Include files that are hidden. Only takes effect on recursive add." ). Default ( false ) ,
73
+ cmds .BoolOption (trickleOptionName , "t" , "Use trickle-dag format for dag generation." ),
74
+ cmds .BoolOption (onlyHashOptionName , "n" , "Only chunk and hash - do not write to disk." ),
75
+ cmds .BoolOption (wrapOptionName , "w" , "Wrap files with a directory object." ),
76
+ cmds .BoolOption (hiddenOptionName , "H" , "Include files that are hidden. Only takes effect on recursive add." ),
79
77
cmds .StringOption (chunkerOptionName , "s" , "Chunking algorithm to use." ),
80
- cmds .BoolOption (pinOptionName , "Pin this object when adding." ). Default ( true ),
78
+ cmds .BoolOption (pinOptionName , "Pin this object when adding. Default: true." ),
81
79
},
82
80
PreRun : func (req cmds.Request ) error {
83
81
if quiet , _ , _ := req .Option (quietOptionName ).Bool (); quiet {
84
82
return nil
85
83
}
86
84
87
- _ , found , _ := req .Option (progressOptionName ).Bool ()
85
+ // ipfs cli progress bar defaults to true
86
+ progress , found , _ := req .Option (progressOptionName ).Bool ()
88
87
if ! found {
89
- req . SetOption ( progressOptionName , true )
88
+ progress = true
90
89
}
91
90
91
+ req .SetOption (progressOptionName , progress )
92
+
92
93
sizeFile , ok := req .Files ().(files.SizeFile )
93
94
if ! ok {
94
95
// we don't need to error, the progress bar just won't know how big the files are
@@ -134,7 +135,11 @@ You can now refer to the added file in a gateway, like so:
134
135
hidden , _ , _ := req .Option (hiddenOptionName ).Bool ()
135
136
silent , _ , _ := req .Option (silentOptionName ).Bool ()
136
137
chunker , _ , _ := req .Option (chunkerOptionName ).String ()
137
- dopin , _ , _ := req .Option (pinOptionName ).Bool ()
138
+ dopin , pin_found , _ := req .Option (pinOptionName ).Bool ()
139
+
140
+ if ! pin_found { // default
141
+ dopin = true
142
+ }
138
143
139
144
if hash {
140
145
nilnode , err := core .NewNode (n .Context (), & core.BuildCfg {
@@ -242,7 +247,7 @@ You can now refer to the added file in a gateway, like so:
242
247
return
243
248
}
244
249
245
- progress , _ , err := req .Option (progressOptionName ).Bool ()
250
+ progress , prgFound , err := req .Option (progressOptionName ).Bool ()
246
251
if err != nil {
247
252
res .SetError (u .ErrCast (), cmds .ErrNormal )
248
253
return
@@ -254,12 +259,17 @@ You can now refer to the added file in a gateway, like so:
254
259
return
255
260
}
256
261
257
- if ! quiet && ! silent {
258
- progress = true
262
+ var showProgressBar bool
263
+ if prgFound {
264
+ showProgressBar = progress
265
+ } else if ! quiet && ! silent {
266
+ showProgressBar = true
259
267
}
260
268
261
269
var bar * pb.ProgressBar
262
- if progress {
270
+
271
+ var terminalWidth int
272
+ if showProgressBar {
263
273
bar = pb .New64 (0 ).SetUnits (pb .U_BYTES )
264
274
bar .ManualUpdate = true
265
275
bar .ShowTimeLeft = false
@@ -286,7 +296,7 @@ You can now refer to the added file in a gateway, like so:
286
296
}
287
297
output := out .(* coreunix.AddedObject )
288
298
if len (output .Hash ) > 0 {
289
- if progress {
299
+ if showProgressBar {
290
300
// clear progress bar line before we print "added x" output
291
301
fmt .Fprintf (res .Stderr (), "\033 [2K\r " )
292
302
}
@@ -299,7 +309,7 @@ You can now refer to the added file in a gateway, like so:
299
309
} else {
300
310
log .Debugf ("add progress: %v %v\n " , output .Name , output .Bytes )
301
311
302
- if ! progress {
312
+ if ! showProgressBar {
303
313
continue
304
314
}
305
315
@@ -315,11 +325,11 @@ You can now refer to the added file in a gateway, like so:
315
325
totalProgress = bar .Add64 (delta )
316
326
}
317
327
318
- if progress {
328
+ if showProgressBar {
319
329
bar .Update ()
320
330
}
321
331
case size := <- sizeChan :
322
- if progress {
332
+ if showProgressBar {
323
333
bar .Total = size
324
334
bar .ShowPercent = true
325
335
bar .ShowBar = true
0 commit comments