@cryptotaxi247 / kubo / commits / 6f796dc27

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 <richard.littauer@gmail.com>

Richard Littauer committed May 10, 2016 at 17:12 UTC 6f796dc272a624bcd8e196658c4b244e308a2a9d
1 file changed +15 -27
core/commands/add.go
+15 -27
@@ -30,9 +30,11 @@ const (
30
31 var AddCmd = &cmds.Command{
32 Helptext: cmds.HelpText{
33 - Tagline: "Add a file or directory to ipfs.",
33 + Tagline: "Add a file to ipfs.",
34 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.
38 `,
39 LongDescription: `
40 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:
63 },
64 Options: []cmds.Option{
65 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),
73 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),
75 },
76 PreRun: func(req cmds.Request) error {
77 if quiet, _, _ := req.Option(quietOptionName).Bool(); quiet {
78 return nil
79 }
80
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 -
81 sizeFile, ok := req.Files().(files.SizeFile)
82 if !ok {
83 // 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:
123 hidden, _, _ := req.Option(hiddenOptionName).Bool()
124 silent, _, _ := req.Option(silentOptionName).Bool()
125 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()
127
128 if hash {
129 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:
210 return
211 }
212
223 - progress, prgFound, err := req.Option(progressOptionName).Bool()
213 + progress, _, err := req.Option(progressOptionName).Bool()
214 if err != nil {
215 res.SetError(u.ErrCast(), cmds.ErrNormal)
216 return
@@ -233,9 +223,7 @@ You can now refer to the added file in a gateway, like so:
223 }
224
225 var showProgressBar bool
236 - if prgFound {
237 - showProgressBar = progress
238 - } else if !quiet && !silent {
226 + if !progress && !quiet && !silent {
227 showProgressBar = true
228 }
229