Skip to content

Commit d8c50b8

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 0e2b4eb commit d8c50b8

File tree

1 file changed

+44
-13
lines changed

1 file changed

+44
-13
lines changed

core/commands/add.go

Lines changed: 44 additions & 13 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,47 @@ 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)
70+
<<<<<<< HEAD
7271
cmds.BoolOption(quietOptionName, "q", "Write minimal output.").Default(false),
7372
cmds.BoolOption(silentOptionName, "Write no output.").Default(false),
7473
cmds.BoolOption(progressOptionName, "p", "Stream progress data."),
7574
cmds.BoolOption(trickleOptionName, "t", "Use trickle-dag format for dag generation.").Default(false),
7675
cmds.BoolOption(onlyHashOptionName, "n", "Only chunk and hash - do not write to disk.").Default(false),
7776
cmds.BoolOption(wrapOptionName, "w", "Wrap files with a directory object.").Default(false),
7877
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
7987
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."),
8189
},
8290
PreRun: func(req cmds.Request) error {
8391
if quiet, _, _ := req.Option(quietOptionName).Bool(); quiet {
8492
return nil
8593
}
8694

95+
<<<<<<< HEAD
8796
_, found, _ := req.Option(progressOptionName).Bool()
8897
if !found {
8998
req.SetOption(progressOptionName, true)
9099
}
91100

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
92111
sizeFile, ok := req.Files().(files.SizeFile)
93112
if !ok {
94113
// 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:
134153
hidden, _, _ := req.Option(hiddenOptionName).Bool()
135154
silent, _, _ := req.Option(silentOptionName).Bool()
136155
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+
}
138161

139162
if hash {
140163
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:
242265
return
243266
}
244267

245-
progress, _, err := req.Option(progressOptionName).Bool()
268+
progress, prgFound, err := req.Option(progressOptionName).Bool()
246269
if err != nil {
247270
res.SetError(u.ErrCast(), cmds.ErrNormal)
248271
return
@@ -254,12 +277,20 @@ You can now refer to the added file in a gateway, like so:
254277
return
255278
}
256279

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
259285
}
260286

261287
var bar *pb.ProgressBar
288+
<<<<<<< HEAD
262289
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
263294
bar = pb.New64(0).SetUnits(pb.U_BYTES)
264295
bar.ManualUpdate = true
265296
bar.ShowTimeLeft = false
@@ -286,7 +317,7 @@ You can now refer to the added file in a gateway, like so:
286317
}
287318
output := out.(*coreunix.AddedObject)
288319
if len(output.Hash) > 0 {
289-
if progress {
320+
if showProgressBar {
290321
// clear progress bar line before we print "added x" output
291322
fmt.Fprintf(res.Stderr(), "\033[2K\r")
292323
}
@@ -299,7 +330,7 @@ You can now refer to the added file in a gateway, like so:
299330
} else {
300331
log.Debugf("add progress: %v %v\n", output.Name, output.Bytes)
301332

302-
if !progress {
333+
if !showProgressBar {
303334
continue
304335
}
305336

@@ -315,11 +346,11 @@ You can now refer to the added file in a gateway, like so:
315346
totalProgress = bar.Add64(delta)
316347
}
317348

318-
if progress {
349+
if showProgressBar {
319350
bar.Update()
320351
}
321352
case size := <-sizeChan:
322-
if progress {
353+
if showProgressBar {
323354
bar.Total = size
324355
bar.ShowPercent = true
325356
bar.ShowBar = true

0 commit comments

Comments
 (0)