Skip to content

Commit

Permalink
Revert "Merge pull request #2657 from ipfs/feature/add-defaults-to-add"
Browse files Browse the repository at this point in the history
This reverts commit da4a4ac, reversing
changes made to 518f7e0.

License: MIT
Signed-off-by: Richard Littauer <richard.littauer@gmail.com>
  • Loading branch information
RichardLitt committed Sep 19, 2016
1 parent 73cd8b3 commit e04abc2
Showing 1 changed file with 44 additions and 13 deletions.
57 changes: 44 additions & 13 deletions core/commands/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <path> to ipfs. Use -r to add directories.
Note that directories are added recursively, to form the ipfs
MerkleDAG.
Adds contents of <path> to ipfs. Use -r to add directories (recursively).
`,
LongDescription: `
Adds contents of <path> to ipfs. Use -r to add directories.
Expand Down Expand Up @@ -69,26 +67,47 @@ 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)
<<<<<<< HEAD
cmds.BoolOption(quietOptionName, "q", "Write minimal output.").Default(false),
cmds.BoolOption(silentOptionName, "Write no output.").Default(false),
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(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."),
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."),
>>>>>>> parent of da4a4ac... Merge pull request #2657 from ipfs/feature/add-defaults-to-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
}

<<<<<<< HEAD
_, found, _ := req.Option(progressOptionName).Bool()
if !found {
req.SetOption(progressOptionName, true)
}

=======
// ipfs cli progress bar defaults to true
progress, found, _ := req.Option(progressOptionName).Bool()
if !found {
progress = true
}

req.SetOption(progressOptionName, progress)

>>>>>>> parent of da4a4ac... Merge pull request #2657 from ipfs/feature/add-defaults-to-add
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
Expand Down Expand Up @@ -134,7 +153,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{
Expand Down Expand Up @@ -242,7 +265,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
Expand All @@ -254,12 +277,20 @@ 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
<<<<<<< HEAD
if progress {
=======
var terminalWidth int
if showProgressBar {
>>>>>>> parent of da4a4ac... Merge pull request #2657 from ipfs/feature/add-defaults-to-add
bar = pb.New64(0).SetUnits(pb.U_BYTES)
bar.ManualUpdate = true
bar.ShowTimeLeft = false
Expand All @@ -286,7 +317,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")
}
Expand All @@ -299,7 +330,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
}

Expand All @@ -315,11 +346,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
Expand Down

0 comments on commit e04abc2

Please sign in to comment.