Revert "Merge pull request #2657 from ipfs/feature/add-defaults-to-add"
In addition to removing the .Default option in the "add" options this also fixes the --progress option so --progress=false work again. This reverts commit da4a4ac0bc26b80457f537b950c5e43130bce242, reversing changes made to 518f7e06a1d480438e0107ed1184750eb84be82c. License: MIT Signed-off-by: Kevin Atkinson <k@kevina.org>
Kevin Atkinson committed
Dec 3, 2016 at 23:33 UTC
aa97a09ba123e4b06512e7de52790c37c5fb9883
1 file changed
+26
-20
core/commands/add.go
+26
-20
@@ -37,11 +37,9 @@ const (
37
38
var AddCmd = &cmds.Command{
39
Helptext: cmds.HelpText{
40
- Tagline: "Add a file to ipfs.",
40
+ Tagline: "Add a file or directory to ipfs.",
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).
43
`,
44
LongDescription: `
45
Adds contents of <path> to ipfs. Use -r to add directories.
@@ -70,15 +68,15 @@ You can now refer to the added file in a gateway, like so:
68
},
69
Options: []cmds.Option{
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."),
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."),
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."),
80
cmds.BoolOption(rawLeavesOptionName, "Use raw blocks for leaf nodes. (experimental)"),
81
},
82
PreRun: func(req cmds.Request) error {
@@ -86,6 +84,7 @@ You can now refer to the added file in a gateway, like so:
84
return nil
85
}
86
87
+ // ipfs cli progress bar defaults to true
88
_, found, _ := req.Option(progressOptionName).Bool()
89
if !found {
90
req.SetOption(progressOptionName, true)
@@ -136,9 +135,13 @@ You can now refer to the added file in a gateway, like so:
135
hidden, _, _ := req.Option(hiddenOptionName).Bool()
136
silent, _, _ := req.Option(silentOptionName).Bool()
137
chunker, _, _ := req.Option(chunkerOptionName).String()
139
- dopin, _, _ := req.Option(pinOptionName).Bool()
138
+ dopin, pin_found, _ := req.Option(pinOptionName).Bool()
139
rawblks, _, _ := req.Option(rawLeavesOptionName).Bool()
140
141
+ if !pin_found { // default
142
+ dopin = true
143
+ }
144
+
145
if hash {
146
nilnode, err := core.NewNode(n.Context(), &core.BuildCfg{
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:
249
return
250
}
251
249
- progress, _, err := req.Option(progressOptionName).Bool()
252
+ progress, prgFound, err := req.Option(progressOptionName).Bool()
253
if err != nil {
254
res.SetError(u.ErrCast(), cmds.ErrNormal)
255
return
@@ -258,12 +261,15 @@ You can now refer to the added file in a gateway, like so:
261
return
262
}
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
269
}
270
271
var bar *pb.ProgressBar
266
- if progress {
272
+ if showProgressBar {
273
bar = pb.New64(0).SetUnits(pb.U_BYTES)
274
bar.ManualUpdate = true
275
bar.ShowTimeLeft = false
@@ -290,7 +296,7 @@ You can now refer to the added file in a gateway, like so:
296
}
297
output := out.(*coreunix.AddedObject)
298
if len(output.Hash) > 0 {
293
- if progress {
299
+ if showProgressBar {
300
// clear progress bar line before we print "added x" output
301
fmt.Fprintf(res.Stderr(), "\033[2K\r")
302
}
@@ -303,7 +309,7 @@ You can now refer to the added file in a gateway, like so:
309
} else {
310
log.Debugf("add progress: %v %v\n", output.Name, output.Bytes)
311
306
- if !progress {
312
+ if !showProgressBar {
313
continue
314
}
315
@@ -319,11 +325,11 @@ You can now refer to the added file in a gateway, like so:
325
totalProgress = bar.Add64(delta)
326
}
327
322
- if progress {
328
+ if showProgressBar {
329
bar.Update()
330
}
331
case size := <-sizeChan:
326
- if progress {
332
+ if showProgressBar {
333
bar.Total = size
334
bar.ShowPercent = true
335
bar.ShowBar = true