From aa97a09ba123e4b06512e7de52790c37c5fb9883 Mon Sep 17 00:00:00 2001 From: Kevin Atkinson Date: Sat, 3 Dec 2016 23:33:29 -0500 Subject: [PATCH 1/3] 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 da4a4ac0bc26b80457f537b950c5e43130bce242, reversing changes made to 518f7e06a1d480438e0107ed1184750eb84be82c. License: MIT Signed-off-by: Kevin Atkinson --- core/commands/add.go | 46 +++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/core/commands/add.go b/core/commands/add.go index 52613ca4c..3ee0d816c 100644 --- a/core/commands/add.go +++ b/core/commands/add.go @@ -37,11 +37,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. @@ -70,15 +68,15 @@ 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."), cmds.BoolOption(rawLeavesOptionName, "Use raw blocks for leaf nodes. (experimental)"), }, PreRun: func(req cmds.Request) error { @@ -86,6 +84,7 @@ You can now refer to the added file in a gateway, like so: return nil } + // ipfs cli progress bar defaults to true _, found, _ := req.Option(progressOptionName).Bool() if !found { req.SetOption(progressOptionName, true) @@ -136,9 +135,13 @@ 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() rawblks, _, _ := req.Option(rawLeavesOptionName).Bool() + if !pin_found { // default + dopin = true + } + if hash { nilnode, err := core.NewNode(n.Context(), &core.BuildCfg{ //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: return } - progress, _, err := req.Option(progressOptionName).Bool() + progress, prgFound, err := req.Option(progressOptionName).Bool() if err != nil { res.SetError(u.ErrCast(), cmds.ErrNormal) return @@ -258,12 +261,15 @@ 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 { + if showProgressBar { bar = pb.New64(0).SetUnits(pb.U_BYTES) bar.ManualUpdate = true bar.ShowTimeLeft = false @@ -290,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") } @@ -303,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 } @@ -319,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 From 0b8e03278505a6ffcfef5eb0eeae013122b7ce5b Mon Sep 17 00:00:00 2001 From: Kevin Atkinson Date: Sat, 3 Dec 2016 23:39:13 -0500 Subject: [PATCH 2/3] add cmd: use .Default(true) for pin option. License: MIT Signed-off-by: Kevin Atkinson --- core/commands/add.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/core/commands/add.go b/core/commands/add.go index 3ee0d816c..8d6e59099 100644 --- a/core/commands/add.go +++ b/core/commands/add.go @@ -76,7 +76,7 @@ You can now refer to the added file in a gateway, like so: 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), cmds.BoolOption(rawLeavesOptionName, "Use raw blocks for leaf nodes. (experimental)"), }, PreRun: func(req cmds.Request) error { @@ -135,13 +135,9 @@ 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, pin_found, _ := req.Option(pinOptionName).Bool() + dopin, _, _ := req.Option(pinOptionName).Bool() rawblks, _, _ := req.Option(rawLeavesOptionName).Bool() - if !pin_found { // default - dopin = true - } - if hash { nilnode, err := core.NewNode(n.Context(), &core.BuildCfg{ //TODO: need this to be true or all files From e92c4445f17fb1d692fced8a59bc4bff881c912d Mon Sep 17 00:00:00 2001 From: Kevin Atkinson Date: Sun, 4 Dec 2016 00:03:56 -0500 Subject: [PATCH 3/3] add cmd: clean up default logic of --progress option License: MIT Signed-off-by: Kevin Atkinson --- core/commands/add.go | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/core/commands/add.go b/core/commands/add.go index 8d6e59099..94e1f3036 100644 --- a/core/commands/add.go +++ b/core/commands/add.go @@ -80,11 +80,14 @@ You can now refer to the added file in a gateway, like so: cmds.BoolOption(rawLeavesOptionName, "Use raw blocks for leaf nodes. (experimental)"), }, PreRun: func(req cmds.Request) error { - if quiet, _, _ := req.Option(quietOptionName).Bool(); quiet { + quiet, _, _ := req.Option(quietOptionName).Bool() + silent, _, _ := req.Option(silentOptionName).Bool() + + if quiet || silent { return nil } - // ipfs cli progress bar defaults to true + // ipfs cli progress bar defaults to true unless quiet or silent is used _, found, _ := req.Option(progressOptionName).Bool() if !found { req.SetOption(progressOptionName, true) @@ -245,27 +248,14 @@ You can now refer to the added file in a gateway, like so: return } - progress, prgFound, err := req.Option(progressOptionName).Bool() + progress, _, err := req.Option(progressOptionName).Bool() if err != nil { res.SetError(u.ErrCast(), cmds.ErrNormal) return } - silent, _, err := req.Option(silentOptionName).Bool() - if err != nil { - res.SetError(u.ErrCast(), cmds.ErrNormal) - return - } - - var showProgressBar bool - if prgFound { - showProgressBar = progress - } else if !quiet && !silent { - showProgressBar = true - } - var bar *pb.ProgressBar - if showProgressBar { + if progress { bar = pb.New64(0).SetUnits(pb.U_BYTES) bar.ManualUpdate = true bar.ShowTimeLeft = false @@ -292,7 +282,7 @@ You can now refer to the added file in a gateway, like so: } output := out.(*coreunix.AddedObject) if len(output.Hash) > 0 { - if showProgressBar { + if progress { // clear progress bar line before we print "added x" output fmt.Fprintf(res.Stderr(), "\033[2K\r") } @@ -305,7 +295,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 !showProgressBar { + if !progress { continue } @@ -321,11 +311,11 @@ You can now refer to the added file in a gateway, like so: totalProgress = bar.Add64(delta) } - if showProgressBar { + if progress { bar.Update() } case size := <-sizeChan: - if showProgressBar { + if progress { bar.Total = size bar.ShowPercent = true bar.ShowBar = true