Skip to content

Commit 9183b5e

Browse files
RichardLittKubuxu
authored andcommitted
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 abeea4f commit 9183b5e

File tree

2 files changed

+28
-30
lines changed

2 files changed

+28
-30
lines changed

core/commands/add.go

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,15 @@ 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.",
34+
Synopsis: `ipfs add <path> [--quiet | -q] [--silent] [--progress | -p]
35+
[--trickle |-t] [--wrap-with-directory | -w] [--hidden | -H]
36+
[--only-hash | -n] [--chunker | -s] [--pin] [--recursive | -r]
37+
`,
3438
ShortDescription: `
35-
Adds contents of <path> to ipfs. Use -r to add directories (recursively).
39+
Adds contents of <path> to ipfs. Use -r to add directories.
40+
Note that directories are added recursively, to form the ipfs
41+
MerkleDAG.
3642
`,
3743
LongDescription: `
3844
Adds contents of <path> to ipfs. Use -r to add directories.
@@ -61,29 +67,21 @@ You can now refer to the added file in a gateway, like so:
6167
},
6268
Options: []cmds.Option{
6369
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."),
70+
cmds.BoolOption(quietOptionName, "q", "Write minimal output.").Default(false),
71+
cmds.BoolOption(silentOptionName, "Write no output.").Default(false),
72+
cmds.BoolOption(progressOptionName, "p", "Stream progress data.").Default(true),
73+
cmds.BoolOption(trickleOptionName, "t", "Use trickle-dag format for dag generation.").Default(false),
74+
cmds.BoolOption(onlyHashOptionName, "n", "Only chunk and hash - do not write to disk.").Default(false),
75+
cmds.BoolOption(wrapOptionName, "w", "Wrap files with a directory object.").Default(false),
76+
cmds.BoolOption(hiddenOptionName, "H", "Include files that are hidden. Only takes effect on recursive add.").Default(false),
7177
cmds.StringOption(chunkerOptionName, "s", "Chunking algorithm to use."),
72-
cmds.BoolOption(pinOptionName, "Pin this object when adding. Default: true."),
78+
cmds.BoolOption(pinOptionName, "Pin this object when adding.").Default(true),
7379
},
7480
PreRun: func(req cmds.Request) error {
7581
if quiet, _, _ := req.Option(quietOptionName).Bool(); quiet {
7682
return nil
7783
}
7884

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-
8785
sizeFile, ok := req.Files().(files.SizeFile)
8886
if !ok {
8987
// we don't need to error, the progress bar just won't know how big the files are
@@ -129,11 +127,7 @@ You can now refer to the added file in a gateway, like so:
129127
hidden, _, _ := req.Option(hiddenOptionName).Bool()
130128
silent, _, _ := req.Option(silentOptionName).Bool()
131129
chunker, _, _ := req.Option(chunkerOptionName).String()
132-
dopin, pin_found, _ := req.Option(pinOptionName).Bool()
133-
134-
if !pin_found { // default
135-
dopin = true
136-
}
130+
dopin, _, _ := req.Option(pinOptionName).Bool()
137131

138132
if hash {
139133
nilnode, err := core.NewNode(n.Context(), &core.BuildCfg{
@@ -220,7 +214,7 @@ You can now refer to the added file in a gateway, like so:
220214
return
221215
}
222216

223-
progress, prgFound, err := req.Option(progressOptionName).Bool()
217+
progress, _, err := req.Option(progressOptionName).Bool()
224218
if err != nil {
225219
res.SetError(u.ErrCast(), cmds.ErrNormal)
226220
return
@@ -233,9 +227,7 @@ You can now refer to the added file in a gateway, like so:
233227
}
234228

235229
var showProgressBar bool
236-
if prgFound {
237-
showProgressBar = progress
238-
} else if !quiet && !silent {
230+
if !progress && !quiet && !silent {
239231
showProgressBar = true
240232
}
241233

test/sharness/t0040-add-and-cat.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,15 @@ test_description="Test add and cat commands"
1111
client_err_add() {
1212
printf "$@\n\n"
1313
echo 'USAGE
14-
ipfs add <path>... - Add a file or directory to ipfs.
14+
ipfs add <path>... - Add a file to ipfs.
1515
16-
Adds contents of <path> to ipfs. Use -r to add directories (recursively).
16+
ipfs add <path> [--quiet | -q] [--silent] [--progress | -p]
17+
[--trickle |-t] [--wrap-with-directory | -w] [--hidden | -H]
18+
[--only-hash | -n] [--chunker | -s] [--pin] [--recursive | -r]
19+
20+
Adds contents of <path> to ipfs. Use -r to add directories.
21+
Note that directories are added recursively, to form the ipfs
22+
MerkleDAG.
1723
1824
Use '"'"'ipfs add --help'"'"' for more information about this command.
1925
'
@@ -360,7 +366,7 @@ test_add_cat_5MB
360366

361367
test_add_cat_expensive
362368

363-
test_add_named_pipe " Post http://$API_ADDR/api/v0/add?encoding=json&progress=true&r=true&stream-channels=true:"
369+
test_add_named_pipe " Post http://$API_ADDR/api/v0/add?encoding=json&r=true&stream-channels=true:"
364370

365371
test_kill_ipfs_daemon
366372

0 commit comments

Comments
 (0)