From 5c7a3931f0f9bc022f7e9035bb0e0969c5914ad4 Mon Sep 17 00:00:00 2001 From: Richard Littauer Date: Mon, 19 Sep 2016 15:04:16 -0400 Subject: [PATCH] Revert "Merge pull request #2657 from ipfs/feature/add-defaults-to-add" This reverts commit da4a4ac0bc26b80457f537b950c5e43130bce242, reversing changes made to 518f7e06a1d480438e0107ed1184750eb84be82c. License: MIT Signed-off-by: Richard Littauer --- core/commands/add.go | 54 ++++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/core/commands/add.go b/core/commands/add.go index a5bf084d333..12d86c48bef 100644 --- a/core/commands/add.go +++ b/core/commands/add.go @@ -36,11 +36,9 @@ const ( var AddCmd = &cmds.Command{ Helptext: cmds.HelpText{ - Tagline: "Add a file to ipfs.", + Tagline: "Add a file or directory to ipfs.", ShortDescription: ` -Adds contents of to ipfs. Use -r to add directories. -Note that directories are added recursively, to form the ipfs -MerkleDAG. +Adds contents of to ipfs. Use -r to add directories (recursively). `, LongDescription: ` Adds contents of to ipfs. Use -r to add directories. @@ -69,26 +67,29 @@ You can now refer to the added file in a gateway, like so: }, Options: []cmds.Option{ cmds.OptionRecursivePath, // a builtin option that allows recursive paths (-r, --recursive) - cmds.BoolOption(quietOptionName, "q", "Write minimal output.").Default(false), - cmds.BoolOption(silentOptionName, "Write no output.").Default(false), + cmds.BoolOption(quietOptionName, "q", "Write minimal output."), + cmds.BoolOption(silentOptionName, "Write no output."), cmds.BoolOption(progressOptionName, "p", "Stream progress data."), - cmds.BoolOption(trickleOptionName, "t", "Use trickle-dag format for dag generation.").Default(false), - cmds.BoolOption(onlyHashOptionName, "n", "Only chunk and hash - do not write to disk.").Default(false), - cmds.BoolOption(wrapOptionName, "w", "Wrap files with a directory object.").Default(false), - cmds.BoolOption(hiddenOptionName, "H", "Include files that are hidden. Only takes effect on recursive add.").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."), + 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."), 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."), }, PreRun: func(req cmds.Request) error { if quiet, _, _ := req.Option(quietOptionName).Bool(); quiet { return nil } - _, found, _ := req.Option(progressOptionName).Bool() + // ipfs cli progress bar defaults to true + progress, found, _ := req.Option(progressOptionName).Bool() if !found { - req.SetOption(progressOptionName, true) + progress = true } + req.SetOption(progressOptionName, progress) + sizeFile, ok := req.Files().(files.SizeFile) if !ok { // we don't need to error, the progress bar just won't know how big the files are @@ -134,7 +135,11 @@ You can now refer to the added file in a gateway, like so: hidden, _, _ := req.Option(hiddenOptionName).Bool() silent, _, _ := req.Option(silentOptionName).Bool() chunker, _, _ := req.Option(chunkerOptionName).String() - dopin, _, _ := req.Option(pinOptionName).Bool() + dopin, pin_found, _ := req.Option(pinOptionName).Bool() + + if !pin_found { // default + dopin = true + } if hash { nilnode, err := core.NewNode(n.Context(), &core.BuildCfg{ @@ -242,7 +247,7 @@ You can now refer to the added file in a gateway, like so: return } - progress, _, err := req.Option(progressOptionName).Bool() + progress, prgFound, err := req.Option(progressOptionName).Bool() if err != nil { res.SetError(u.ErrCast(), cmds.ErrNormal) return @@ -254,12 +259,17 @@ You can now refer to the added file in a gateway, like so: return } - if !quiet && !silent { - progress = true + var showProgressBar bool + if prgFound { + showProgressBar = progress + } else if !quiet && !silent { + showProgressBar = true } var bar *pb.ProgressBar - if progress { + + var terminalWidth int + if showProgressBar { bar = pb.New64(0).SetUnits(pb.U_BYTES) bar.ManualUpdate = true bar.ShowTimeLeft = false @@ -286,7 +296,7 @@ You can now refer to the added file in a gateway, like so: } output := out.(*coreunix.AddedObject) if len(output.Hash) > 0 { - if progress { + if showProgressBar { // clear progress bar line before we print "added x" output fmt.Fprintf(res.Stderr(), "\033[2K\r") } @@ -299,7 +309,7 @@ You can now refer to the added file in a gateway, like so: } else { log.Debugf("add progress: %v %v\n", output.Name, output.Bytes) - if !progress { + if !showProgressBar { continue } @@ -315,11 +325,11 @@ You can now refer to the added file in a gateway, like so: totalProgress = bar.Add64(delta) } - if progress { + if showProgressBar { bar.Update() } case size := <-sizeChan: - if progress { + if showProgressBar { bar.Total = size bar.ShowPercent = true bar.ShowBar = true