提交 aa97a09b 作者: Kevin Atkinson

Revert "Merge pull request #2657 from ipfs/feature/add-defaults-to-add"

In addition to removing the .Default option in the "add" options this
also fixes the --progress option so --progress=false work again.

This reverts commit da4a4ac0, reversing
changes made to 518f7e06.

License: MIT
Signed-off-by: 's avatarKevin Atkinson <k@kevina.org>
上级 4f38c88c
...@@ -37,11 +37,9 @@ const ( ...@@ -37,11 +37,9 @@ const (
var AddCmd = &cmds.Command{ var AddCmd = &cmds.Command{
Helptext: cmds.HelpText{ Helptext: cmds.HelpText{
Tagline: "Add a file to ipfs.", Tagline: "Add a file or directory to ipfs.",
ShortDescription: ` ShortDescription: `
Adds contents of <path> to ipfs. Use -r to add directories. Adds contents of <path> to ipfs. Use -r to add directories (recursively).
Note that directories are added recursively, to form the ipfs
MerkleDAG.
`, `,
LongDescription: ` LongDescription: `
Adds contents of <path> to ipfs. Use -r to add directories. Adds contents of <path> to ipfs. Use -r to add directories.
...@@ -70,15 +68,15 @@ You can now refer to the added file in a gateway, like so: ...@@ -70,15 +68,15 @@ You can now refer to the added file in a gateway, like so:
}, },
Options: []cmds.Option{ Options: []cmds.Option{
cmds.OptionRecursivePath, // a builtin option that allows recursive paths (-r, --recursive) cmds.OptionRecursivePath, // a builtin option that allows recursive paths (-r, --recursive)
cmds.BoolOption(quietOptionName, "q", "Write minimal output.").Default(false), cmds.BoolOption(quietOptionName, "q", "Write minimal output."),
cmds.BoolOption(silentOptionName, "Write no output.").Default(false), cmds.BoolOption(silentOptionName, "Write no output."),
cmds.BoolOption(progressOptionName, "p", "Stream progress data."), cmds.BoolOption(progressOptionName, "p", "Stream progress data."),
cmds.BoolOption(trickleOptionName, "t", "Use trickle-dag format for dag generation.").Default(false), cmds.BoolOption(trickleOptionName, "t", "Use trickle-dag format for dag generation."),
cmds.BoolOption(onlyHashOptionName, "n", "Only chunk and hash - do not write to disk.").Default(false), cmds.BoolOption(onlyHashOptionName, "n", "Only chunk and hash - do not write to disk."),
cmds.BoolOption(wrapOptionName, "w", "Wrap files with a directory object.").Default(false), cmds.BoolOption(wrapOptionName, "w", "Wrap files with a directory object."),
cmds.BoolOption(hiddenOptionName, "H", "Include files that are hidden. Only takes effect on recursive add.").Default(false), cmds.BoolOption(hiddenOptionName, "H", "Include files that are hidden. Only takes effect on recursive add."),
cmds.StringOption(chunkerOptionName, "s", "Chunking algorithm to use."), cmds.StringOption(chunkerOptionName, "s", "Chunking algorithm to use."),
cmds.BoolOption(pinOptionName, "Pin this object when adding.").Default(true), cmds.BoolOption(pinOptionName, "Pin this object when adding. Default: true."),
cmds.BoolOption(rawLeavesOptionName, "Use raw blocks for leaf nodes. (experimental)"), cmds.BoolOption(rawLeavesOptionName, "Use raw blocks for leaf nodes. (experimental)"),
}, },
PreRun: func(req cmds.Request) error { PreRun: func(req cmds.Request) error {
...@@ -86,6 +84,7 @@ You can now refer to the added file in a gateway, like so: ...@@ -86,6 +84,7 @@ You can now refer to the added file in a gateway, like so:
return nil return nil
} }
// ipfs cli progress bar defaults to true
_, found, _ := req.Option(progressOptionName).Bool() _, found, _ := req.Option(progressOptionName).Bool()
if !found { if !found {
req.SetOption(progressOptionName, true) req.SetOption(progressOptionName, true)
...@@ -136,9 +135,13 @@ You can now refer to the added file in a gateway, like so: ...@@ -136,9 +135,13 @@ You can now refer to the added file in a gateway, like so:
hidden, _, _ := req.Option(hiddenOptionName).Bool() hidden, _, _ := req.Option(hiddenOptionName).Bool()
silent, _, _ := req.Option(silentOptionName).Bool() silent, _, _ := req.Option(silentOptionName).Bool()
chunker, _, _ := req.Option(chunkerOptionName).String() chunker, _, _ := req.Option(chunkerOptionName).String()
dopin, _, _ := req.Option(pinOptionName).Bool() dopin, pin_found, _ := req.Option(pinOptionName).Bool()
rawblks, _, _ := req.Option(rawLeavesOptionName).Bool() rawblks, _, _ := req.Option(rawLeavesOptionName).Bool()
if !pin_found { // default
dopin = true
}
if hash { if hash {
nilnode, err := core.NewNode(n.Context(), &core.BuildCfg{ nilnode, err := core.NewNode(n.Context(), &core.BuildCfg{
//TODO: need this to be true or all files //TODO: need this to be true or all files
...@@ -246,7 +249,7 @@ You can now refer to the added file in a gateway, like so: ...@@ -246,7 +249,7 @@ You can now refer to the added file in a gateway, like so:
return return
} }
progress, _, err := req.Option(progressOptionName).Bool() progress, prgFound, err := req.Option(progressOptionName).Bool()
if err != nil { if err != nil {
res.SetError(u.ErrCast(), cmds.ErrNormal) res.SetError(u.ErrCast(), cmds.ErrNormal)
return return
...@@ -258,12 +261,15 @@ You can now refer to the added file in a gateway, like so: ...@@ -258,12 +261,15 @@ You can now refer to the added file in a gateway, like so:
return return
} }
if !quiet && !silent { var showProgressBar bool
progress = true if prgFound {
showProgressBar = progress
} else if !quiet && !silent {
showProgressBar = true
} }
var bar *pb.ProgressBar var bar *pb.ProgressBar
if progress { if showProgressBar {
bar = pb.New64(0).SetUnits(pb.U_BYTES) bar = pb.New64(0).SetUnits(pb.U_BYTES)
bar.ManualUpdate = true bar.ManualUpdate = true
bar.ShowTimeLeft = false bar.ShowTimeLeft = false
...@@ -290,7 +296,7 @@ You can now refer to the added file in a gateway, like so: ...@@ -290,7 +296,7 @@ You can now refer to the added file in a gateway, like so:
} }
output := out.(*coreunix.AddedObject) output := out.(*coreunix.AddedObject)
if len(output.Hash) > 0 { if len(output.Hash) > 0 {
if progress { if showProgressBar {
// clear progress bar line before we print "added x" output // clear progress bar line before we print "added x" output
fmt.Fprintf(res.Stderr(), "\033[2K\r") fmt.Fprintf(res.Stderr(), "\033[2K\r")
} }
...@@ -303,7 +309,7 @@ You can now refer to the added file in a gateway, like so: ...@@ -303,7 +309,7 @@ You can now refer to the added file in a gateway, like so:
} else { } else {
log.Debugf("add progress: %v %v\n", output.Name, output.Bytes) log.Debugf("add progress: %v %v\n", output.Name, output.Bytes)
if !progress { if !showProgressBar {
continue continue
} }
...@@ -319,11 +325,11 @@ You can now refer to the added file in a gateway, like so: ...@@ -319,11 +325,11 @@ You can now refer to the added file in a gateway, like so:
totalProgress = bar.Add64(delta) totalProgress = bar.Add64(delta)
} }
if progress { if showProgressBar {
bar.Update() bar.Update()
} }
case size := <-sizeChan: case size := <-sizeChan:
if progress { if showProgressBar {
bar.Total = size bar.Total = size
bar.ShowPercent = true bar.ShowPercent = true
bar.ShowBar = true bar.ShowBar = true
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论