Skip to content

Commit aa97a09

Browse files
committed
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 da4a4ac, reversing changes made to 518f7e0. License: MIT Signed-off-by: Kevin Atkinson <[email protected]>
1 parent 4f38c88 commit aa97a09

File tree

1 file changed

+26
-20
lines changed

1 file changed

+26
-20
lines changed

core/commands/add.go

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,9 @@ const (
3737

3838
var AddCmd = &cmds.Command{
3939
Helptext: cmds.HelpText{
40-
Tagline: "Add a file to ipfs.",
40+
Tagline: "Add a file or directory to ipfs.",
4141
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).
4543
`,
4644
LongDescription: `
4745
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:
7068
},
7169
Options: []cmds.Option{
7270
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."),
7573
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."),
8078
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."),
8280
cmds.BoolOption(rawLeavesOptionName, "Use raw blocks for leaf nodes. (experimental)"),
8381
},
8482
PreRun: func(req cmds.Request) error {
8583
if quiet, _, _ := req.Option(quietOptionName).Bool(); quiet {
8684
return nil
8785
}
8886

87+
// ipfs cli progress bar defaults to true
8988
_, found, _ := req.Option(progressOptionName).Bool()
9089
if !found {
9190
req.SetOption(progressOptionName, true)
@@ -136,9 +135,13 @@ You can now refer to the added file in a gateway, like so:
136135
hidden, _, _ := req.Option(hiddenOptionName).Bool()
137136
silent, _, _ := req.Option(silentOptionName).Bool()
138137
chunker, _, _ := req.Option(chunkerOptionName).String()
139-
dopin, _, _ := req.Option(pinOptionName).Bool()
138+
dopin, pin_found, _ := req.Option(pinOptionName).Bool()
140139
rawblks, _, _ := req.Option(rawLeavesOptionName).Bool()
141140

141+
if !pin_found { // default
142+
dopin = true
143+
}
144+
142145
if hash {
143146
nilnode, err := core.NewNode(n.Context(), &core.BuildCfg{
144147
//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:
246249
return
247250
}
248251

249-
progress, _, err := req.Option(progressOptionName).Bool()
252+
progress, prgFound, err := req.Option(progressOptionName).Bool()
250253
if err != nil {
251254
res.SetError(u.ErrCast(), cmds.ErrNormal)
252255
return
@@ -258,12 +261,15 @@ You can now refer to the added file in a gateway, like so:
258261
return
259262
}
260263

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
263269
}
264270

265271
var bar *pb.ProgressBar
266-
if progress {
272+
if showProgressBar {
267273
bar = pb.New64(0).SetUnits(pb.U_BYTES)
268274
bar.ManualUpdate = true
269275
bar.ShowTimeLeft = false
@@ -290,7 +296,7 @@ You can now refer to the added file in a gateway, like so:
290296
}
291297
output := out.(*coreunix.AddedObject)
292298
if len(output.Hash) > 0 {
293-
if progress {
299+
if showProgressBar {
294300
// clear progress bar line before we print "added x" output
295301
fmt.Fprintf(res.Stderr(), "\033[2K\r")
296302
}
@@ -303,7 +309,7 @@ You can now refer to the added file in a gateway, like so:
303309
} else {
304310
log.Debugf("add progress: %v %v\n", output.Name, output.Bytes)
305311

306-
if !progress {
312+
if !showProgressBar {
307313
continue
308314
}
309315

@@ -319,11 +325,11 @@ You can now refer to the added file in a gateway, like so:
319325
totalProgress = bar.Add64(delta)
320326
}
321327

322-
if progress {
328+
if showProgressBar {
323329
bar.Update()
324330
}
325331
case size := <-sizeChan:
326-
if progress {
332+
if showProgressBar {
327333
bar.Total = size
328334
bar.ShowPercent = true
329335
bar.ShowBar = true

0 commit comments

Comments
 (0)