mirror of
https://github.com/ipfs/kubo.git
synced 2025-07-01 10:49:24 +08:00
feat: add quieter option to add
It disables all outputs apart from the last hash. Useful for adding directories as you won't have to do `| tail -1` License: MIT Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch> DRY up License: MIT Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
This commit is contained in:
@ -26,6 +26,7 @@ var ErrDepthLimitExceeded = fmt.Errorf("depth limit exceeded")
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
quietOptionName = "quiet"
|
quietOptionName = "quiet"
|
||||||
|
quieterOptionName = "quieter"
|
||||||
silentOptionName = "silent"
|
silentOptionName = "silent"
|
||||||
progressOptionName = "progress"
|
progressOptionName = "progress"
|
||||||
trickleOptionName = "trickle"
|
trickleOptionName = "trickle"
|
||||||
@ -73,6 +74,7 @@ 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."),
|
cmds.BoolOption(quietOptionName, "q", "Write minimal output."),
|
||||||
|
cmds.BoolOption(quieterOptionName, "Q", "Write only final hash."),
|
||||||
cmds.BoolOption(silentOptionName, "Write no output."),
|
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."),
|
cmds.BoolOption(trickleOptionName, "t", "Use trickle-dag format for dag generation."),
|
||||||
@ -87,6 +89,9 @@ You can now refer to the added file in a gateway, like so:
|
|||||||
},
|
},
|
||||||
PreRun: func(req cmds.Request) error {
|
PreRun: func(req cmds.Request) error {
|
||||||
quiet, _, _ := req.Option(quietOptionName).Bool()
|
quiet, _, _ := req.Option(quietOptionName).Bool()
|
||||||
|
quieter, _, _ := req.Option(quieterOptionName).Bool()
|
||||||
|
quiet = quiet || quieter
|
||||||
|
|
||||||
silent, _, _ := req.Option(silentOptionName).Bool()
|
silent, _, _ := req.Option(silentOptionName).Bool()
|
||||||
|
|
||||||
if quiet || silent {
|
if quiet || silent {
|
||||||
@ -278,17 +283,11 @@ You can now refer to the added file in a gateway, like so:
|
|||||||
}
|
}
|
||||||
res.SetOutput(nil)
|
res.SetOutput(nil)
|
||||||
|
|
||||||
quiet, _, err := req.Option("quiet").Bool()
|
quiet, _, _ := req.Option(quietOptionName).Bool()
|
||||||
if err != nil {
|
quieter, _, _ := req.Option(quieterOptionName).Bool()
|
||||||
res.SetError(u.ErrCast(), cmds.ErrNormal)
|
quiet = quiet || quieter
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
progress, _, err := req.Option(progressOptionName).Bool()
|
progress, _, _ := req.Option(progressOptionName).Bool()
|
||||||
if err != nil {
|
|
||||||
res.SetError(u.ErrCast(), cmds.ErrNormal)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var bar *pb.ProgressBar
|
var bar *pb.ProgressBar
|
||||||
if progress {
|
if progress {
|
||||||
@ -307,6 +306,7 @@ You can now refer to the added file in a gateway, like so:
|
|||||||
}
|
}
|
||||||
|
|
||||||
lastFile := ""
|
lastFile := ""
|
||||||
|
lastHash := ""
|
||||||
var totalProgress, prevFiles, lastBytes int64
|
var totalProgress, prevFiles, lastBytes int64
|
||||||
|
|
||||||
LOOP:
|
LOOP:
|
||||||
@ -314,10 +314,18 @@ You can now refer to the added file in a gateway, like so:
|
|||||||
select {
|
select {
|
||||||
case out, ok := <-outChan:
|
case out, ok := <-outChan:
|
||||||
if !ok {
|
if !ok {
|
||||||
|
if quieter {
|
||||||
|
fmt.Fprintln(res.Stdout(), lastHash)
|
||||||
|
}
|
||||||
break LOOP
|
break LOOP
|
||||||
}
|
}
|
||||||
output := out.(*coreunix.AddedObject)
|
output := out.(*coreunix.AddedObject)
|
||||||
if len(output.Hash) > 0 {
|
if len(output.Hash) > 0 {
|
||||||
|
lastHash = output.Hash
|
||||||
|
if quieter {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
if progress {
|
if progress {
|
||||||
// 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")
|
||||||
@ -327,7 +335,6 @@ You can now refer to the added file in a gateway, like so:
|
|||||||
} else {
|
} else {
|
||||||
fmt.Fprintf(res.Stdout(), "added %s %s\n", output.Hash, output.Name)
|
fmt.Fprintf(res.Stdout(), "added %s %s\n", output.Hash, output.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
log.Debugf("add progress: %v %v\n", output.Name, output.Bytes)
|
log.Debugf("add progress: %v %v\n", output.Name, output.Bytes)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user