Skip to content

Commit 5c7a393

Browse files
committed
Revert "Merge pull request #2657 from ipfs/feature/add-defaults-to-add"
This reverts commit da4a4ac, reversing changes made to 518f7e0. License: MIT Signed-off-by: Richard Littauer <[email protected]>
1 parent 73cd8b3 commit 5c7a393

File tree

1 file changed

+32
-22
lines changed

1 file changed

+32
-22
lines changed

core/commands/add.go

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,9 @@ const (
3636

3737
var AddCmd = &cmds.Command{
3838
Helptext: cmds.HelpText{
39-
Tagline: "Add a file to ipfs.",
39+
Tagline: "Add a file or directory to ipfs.",
4040
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).
4442
`,
4543
LongDescription: `
4644
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:
6967
},
7068
Options: []cmds.Option{
7169
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."),
7472
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."),
7977
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."),
8179
},
8280
PreRun: func(req cmds.Request) error {
8381
if quiet, _, _ := req.Option(quietOptionName).Bool(); quiet {
8482
return nil
8583
}
8684

87-
_, found, _ := req.Option(progressOptionName).Bool()
85+
// ipfs cli progress bar defaults to true
86+
progress, found, _ := req.Option(progressOptionName).Bool()
8887
if !found {
89-
req.SetOption(progressOptionName, true)
88+
progress = true
9089
}
9190

91+
req.SetOption(progressOptionName, progress)
92+
9293
sizeFile, ok := req.Files().(files.SizeFile)
9394
if !ok {
9495
// 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:
134135
hidden, _, _ := req.Option(hiddenOptionName).Bool()
135136
silent, _, _ := req.Option(silentOptionName).Bool()
136137
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+
}
138143

139144
if hash {
140145
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:
242247
return
243248
}
244249

245-
progress, _, err := req.Option(progressOptionName).Bool()
250+
progress, prgFound, err := req.Option(progressOptionName).Bool()
246251
if err != nil {
247252
res.SetError(u.ErrCast(), cmds.ErrNormal)
248253
return
@@ -254,12 +259,17 @@ You can now refer to the added file in a gateway, like so:
254259
return
255260
}
256261

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
259267
}
260268

261269
var bar *pb.ProgressBar
262-
if progress {
270+
271+
var terminalWidth int
272+
if showProgressBar {
263273
bar = pb.New64(0).SetUnits(pb.U_BYTES)
264274
bar.ManualUpdate = true
265275
bar.ShowTimeLeft = false
@@ -286,7 +296,7 @@ You can now refer to the added file in a gateway, like so:
286296
}
287297
output := out.(*coreunix.AddedObject)
288298
if len(output.Hash) > 0 {
289-
if progress {
299+
if showProgressBar {
290300
// clear progress bar line before we print "added x" output
291301
fmt.Fprintf(res.Stderr(), "\033[2K\r")
292302
}
@@ -299,7 +309,7 @@ You can now refer to the added file in a gateway, like so:
299309
} else {
300310
log.Debugf("add progress: %v %v\n", output.Name, output.Bytes)
301311

302-
if !progress {
312+
if !showProgressBar {
303313
continue
304314
}
305315

@@ -315,11 +325,11 @@ You can now refer to the added file in a gateway, like so:
315325
totalProgress = bar.Add64(delta)
316326
}
317327

318-
if progress {
328+
if showProgressBar {
319329
bar.Update()
320330
}
321331
case size := <-sizeChan:
322-
if progress {
332+
if showProgressBar {
323333
bar.Total = size
324334
bar.ShowPercent = true
325335
bar.ShowBar = true

0 commit comments

Comments
 (0)