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