diff --git a/core/commands/add.go b/core/commands/add.go index a5bf084d333..b75577ffb1d 100644 --- a/core/commands/add.go +++ b/core/commands/add.go @@ -36,16 +36,17 @@ 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. -Note that directories are added recursively, to form the ipfs -MerkleDAG. +Adds contents of to ipfs. Use -r to add directories, recursively. + +Files and directories will be chunked and imported into ipfs. File chunks +and directory entries will be linked with cryptographic hashes, forming +an ipfs merkledag. For more information about how file importing works +and the merkledag data structures, see . The wrap option, '-w', wraps the file (or files, if using the recursive option) in a directory. This directory contains only @@ -69,13 +70,13 @@ 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), }, @@ -242,7 +243,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 +255,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 @@ -286,7 +290,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 +303,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 +319,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