Skip to content

Commit 6f796dc

Browse files
committed
Add Defaults to ipfs add
I didn't bother with Chunker, because I think that is a much wider PR. These should all be solid, though. Redid some of the logic to make it smoother. Part of #2484. License: MIT Signed-off-by: Richard Littauer <[email protected]>
1 parent 518f7e0 commit 6f796dc

File tree

1 file changed

+15
-27
lines changed

1 file changed

+15
-27
lines changed

core/commands/add.go

+15-27
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ const (
3030

3131
var AddCmd = &cmds.Command{
3232
Helptext: cmds.HelpText{
33-
Tagline: "Add a file or directory to ipfs.",
33+
Tagline: "Add a file to ipfs.",
3434
ShortDescription: `
35-
Adds contents of <path> to ipfs. Use -r to add directories (recursively).
35+
Adds contents of <path> to ipfs. Use -r to add directories.
36+
Note that directories are added recursively, to form the ipfs
37+
MerkleDAG.
3638
`,
3739
LongDescription: `
3840
Adds contents of <path> to ipfs. Use -r to add directories.
@@ -61,29 +63,21 @@ You can now refer to the added file in a gateway, like so:
6163
},
6264
Options: []cmds.Option{
6365
cmds.OptionRecursivePath, // a builtin option that allows recursive paths (-r, --recursive)
64-
cmds.BoolOption(quietOptionName, "q", "Write minimal output."),
65-
cmds.BoolOption(silentOptionName, "Write no output."),
66-
cmds.BoolOption(progressOptionName, "p", "Stream progress data."),
67-
cmds.BoolOption(trickleOptionName, "t", "Use trickle-dag format for dag generation."),
68-
cmds.BoolOption(onlyHashOptionName, "n", "Only chunk and hash - do not write to disk."),
69-
cmds.BoolOption(wrapOptionName, "w", "Wrap files with a directory object."),
70-
cmds.BoolOption(hiddenOptionName, "H", "Include files that are hidden. Only takes effect on recursive add."),
66+
cmds.BoolOption(quietOptionName, "q", "Write minimal output.").Default(false),
67+
cmds.BoolOption(silentOptionName, "Write no output.").Default(false),
68+
cmds.BoolOption(progressOptionName, "p", "Stream progress data.").Default(true),
69+
cmds.BoolOption(trickleOptionName, "t", "Use trickle-dag format for dag generation.").Default(false),
70+
cmds.BoolOption(onlyHashOptionName, "n", "Only chunk and hash - do not write to disk.").Default(false),
71+
cmds.BoolOption(wrapOptionName, "w", "Wrap files with a directory object.").Default(false),
72+
cmds.BoolOption(hiddenOptionName, "H", "Include files that are hidden. Only takes effect on recursive add.").Default(false),
7173
cmds.StringOption(chunkerOptionName, "s", "Chunking algorithm to use."),
72-
cmds.BoolOption(pinOptionName, "Pin this object when adding. Default: true."),
74+
cmds.BoolOption(pinOptionName, "Pin this object when adding.").Default(true),
7375
},
7476
PreRun: func(req cmds.Request) error {
7577
if quiet, _, _ := req.Option(quietOptionName).Bool(); quiet {
7678
return nil
7779
}
7880

79-
// ipfs cli progress bar defaults to true
80-
progress, found, _ := req.Option(progressOptionName).Bool()
81-
if !found {
82-
progress = true
83-
}
84-
85-
req.SetOption(progressOptionName, progress)
86-
8781
sizeFile, ok := req.Files().(files.SizeFile)
8882
if !ok {
8983
// we don't need to error, the progress bar just won't know how big the files are
@@ -129,11 +123,7 @@ You can now refer to the added file in a gateway, like so:
129123
hidden, _, _ := req.Option(hiddenOptionName).Bool()
130124
silent, _, _ := req.Option(silentOptionName).Bool()
131125
chunker, _, _ := req.Option(chunkerOptionName).String()
132-
dopin, pin_found, _ := req.Option(pinOptionName).Bool()
133-
134-
if !pin_found { // default
135-
dopin = true
136-
}
126+
dopin, _, _ := req.Option(pinOptionName).Bool()
137127

138128
if hash {
139129
nilnode, err := core.NewNode(n.Context(), &core.BuildCfg{
@@ -220,7 +210,7 @@ You can now refer to the added file in a gateway, like so:
220210
return
221211
}
222212

223-
progress, prgFound, err := req.Option(progressOptionName).Bool()
213+
progress, _, err := req.Option(progressOptionName).Bool()
224214
if err != nil {
225215
res.SetError(u.ErrCast(), cmds.ErrNormal)
226216
return
@@ -233,9 +223,7 @@ You can now refer to the added file in a gateway, like so:
233223
}
234224

235225
var showProgressBar bool
236-
if prgFound {
237-
showProgressBar = progress
238-
} else if !quiet && !silent {
226+
if !progress && !quiet && !silent {
239227
showProgressBar = true
240228
}
241229

0 commit comments

Comments
 (0)