@@ -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,47 @@ 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)
70
+ << << << < HEAD
72
71
cmds .BoolOption (quietOptionName , "q" , "Write minimal output." ).Default (false ),
73
72
cmds .BoolOption (silentOptionName , "Write no output." ).Default (false ),
74
73
cmds .BoolOption (progressOptionName , "p" , "Stream progress data." ),
75
74
cmds .BoolOption (trickleOptionName , "t" , "Use trickle-dag format for dag generation." ).Default (false ),
76
75
cmds .BoolOption (onlyHashOptionName , "n" , "Only chunk and hash - do not write to disk." ).Default (false ),
77
76
cmds .BoolOption (wrapOptionName , "w" , "Wrap files with a directory object." ).Default (false ),
78
77
cmds .BoolOption (hiddenOptionName , "H" , "Include files that are hidden. Only takes effect on recursive add." ).Default (false ),
78
+ == == == =
79
+ cmds .BoolOption (quietOptionName , "q" , "Write minimal output." ),
80
+ cmds .BoolOption (silentOptionName , "Write no output." ),
81
+ cmds .BoolOption (progressOptionName , "p" , "Stream progress data." ),
82
+ cmds .BoolOption (trickleOptionName , "t" , "Use trickle-dag format for dag generation." ),
83
+ cmds .BoolOption (onlyHashOptionName , "n" , "Only chunk and hash - do not write to disk." ),
84
+ cmds .BoolOption (wrapOptionName , "w" , "Wrap files with a directory object." ),
85
+ cmds .BoolOption (hiddenOptionName , "H" , "Include files that are hidden. Only takes effect on recursive add." ),
86
+ >> >> >> > parent of da4a4ac ... Merge pull request #2657 from ipfs / feature / add - defaults - to - add
79
87
cmds .StringOption (chunkerOptionName , "s" , "Chunking algorithm to use." ),
80
- cmds .BoolOption (pinOptionName , "Pin this object when adding." ). Default ( true ),
88
+ cmds .BoolOption (pinOptionName , "Pin this object when adding. Default: true." ),
81
89
},
82
90
PreRun : func (req cmds.Request ) error {
83
91
if quiet , _ , _ := req .Option (quietOptionName ).Bool (); quiet {
84
92
return nil
85
93
}
86
94
95
+ << << << < HEAD
87
96
_ , found , _ := req .Option (progressOptionName ).Bool ()
88
97
if ! found {
89
98
req .SetOption (progressOptionName , true )
90
99
}
91
100
101
+ == == == =
102
+ // ipfs cli progress bar defaults to true
103
+ progress , found , _ := req .Option (progressOptionName ).Bool ()
104
+ if ! found {
105
+ progress = true
106
+ }
107
+
108
+ req .SetOption (progressOptionName , progress )
109
+
110
+ >> >> >> > parent of da4a4ac... Merge pull request #2657 from ipfs / feature / add - defaults - to - add
92
111
sizeFile , ok := req .Files ().(files.SizeFile )
93
112
if ! ok {
94
113
// we don't need to error, the progress bar just won't know how big the files are
@@ -134,7 +153,11 @@ You can now refer to the added file in a gateway, like so:
134
153
hidden , _ , _ := req .Option (hiddenOptionName ).Bool ()
135
154
silent , _ , _ := req .Option (silentOptionName ).Bool ()
136
155
chunker , _ , _ := req .Option (chunkerOptionName ).String ()
137
- dopin , _ , _ := req .Option (pinOptionName ).Bool ()
156
+ dopin , pin_found , _ := req .Option (pinOptionName ).Bool ()
157
+
158
+ if ! pin_found { // default
159
+ dopin = true
160
+ }
138
161
139
162
if hash {
140
163
nilnode , err := core .NewNode (n .Context (), & core.BuildCfg {
@@ -242,7 +265,7 @@ You can now refer to the added file in a gateway, like so:
242
265
return
243
266
}
244
267
245
- progress , _ , err := req .Option (progressOptionName ).Bool ()
268
+ progress , prgFound , err := req .Option (progressOptionName ).Bool ()
246
269
if err != nil {
247
270
res .SetError (u .ErrCast (), cmds .ErrNormal )
248
271
return
@@ -254,12 +277,20 @@ You can now refer to the added file in a gateway, like so:
254
277
return
255
278
}
256
279
257
- if ! quiet && ! silent {
258
- progress = true
280
+ var showProgressBar bool
281
+ if prgFound {
282
+ showProgressBar = progress
283
+ } else if ! quiet && ! silent {
284
+ showProgressBar = true
259
285
}
260
286
261
287
var bar * pb.ProgressBar
288
+ << << << < HEAD
262
289
if progress {
290
+ == == == =
291
+ var terminalWidth int
292
+ if showProgressBar {
293
+ >> >> >> > parent of da4a4ac... Merge pull request #2657 from ipfs / feature / add - defaults - to - add
263
294
bar = pb .New64 (0 ).SetUnits (pb .U_BYTES )
264
295
bar .ManualUpdate = true
265
296
bar .ShowTimeLeft = false
@@ -286,7 +317,7 @@ You can now refer to the added file in a gateway, like so:
286
317
}
287
318
output := out .(* coreunix.AddedObject )
288
319
if len (output .Hash ) > 0 {
289
- if progress {
320
+ if showProgressBar {
290
321
// clear progress bar line before we print "added x" output
291
322
fmt .Fprintf (res .Stderr (), "\033 [2K\r " )
292
323
}
@@ -299,7 +330,7 @@ You can now refer to the added file in a gateway, like so:
299
330
} else {
300
331
log .Debugf ("add progress: %v %v\n " , output .Name , output .Bytes )
301
332
302
- if ! progress {
333
+ if ! showProgressBar {
303
334
continue
304
335
}
305
336
@@ -315,11 +346,11 @@ You can now refer to the added file in a gateway, like so:
315
346
totalProgress = bar .Add64 (delta )
316
347
}
317
348
318
- if progress {
349
+ if showProgressBar {
319
350
bar .Update ()
320
351
}
321
352
case size := <- sizeChan :
322
- if progress {
353
+ if showProgressBar {
323
354
bar .Total = size
324
355
bar .ShowPercent = true
325
356
bar .ShowBar = true
0 commit comments