Skip to content

Commit

Permalink
Add support for dereferencing command-line arguments
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Dominic Della Valle <[email protected]>
  • Loading branch information
djdv committed Nov 29, 2018
1 parent 40ce8a7 commit 9847a9f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 7 additions & 2 deletions cli/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ import (
"sort"
"strings"

"github.com/ipfs/go-ipfs-cmds"

osh "github.com/Kubuxu/go-os-helper"
"github.com/ipfs/go-ipfs-cmdkit"
"github.com/ipfs/go-ipfs-cmds"
"github.com/ipfs/go-ipfs-files"
logging "github.com/ipfs/go-log"
)
Expand Down Expand Up @@ -265,6 +264,12 @@ func parseArgs(req *cmds.Request, root *cmds.Command, stdin *os.File) error {
fpath = stdin.Name()
file = files.NewReaderFile("", fpath, r, nil)
} else {
if derefArgs, _ := req.Options[cmds.DerefLong].(bool); derefArgs {
var err error // don't shadow fpath
if fpath, err = filepath.EvalSymlinks(fpath); err != nil {
return err
}
}
nf, err := appendFile(fpath, argDef, isRecursive(req), isHidden(req))
if err != nil {
return err
Expand Down
6 changes: 4 additions & 2 deletions opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ const (
TimeoutOpt = "timeout"
OptShortHelp = "h"
OptLongHelp = "help"
DerefLong = "dereference-command-line"
)

// options that are used by this package
var OptionEncodingType = cmdkit.StringOption(EncLong, EncShort, "The encoding type the output should be encoded with (json, xml, or text)").WithDefault("text")
var OptionRecursivePath = cmdkit.BoolOption(RecLong, RecShort, "Add directory paths recursively").WithDefault(false)
var OptionRecursivePath = cmdkit.BoolOption(RecLong, RecShort, "Add directory paths recursively")
var OptionStreamChannels = cmdkit.BoolOption(ChanOpt, "Stream channel output")
var OptionTimeout = cmdkit.StringOption(TimeoutOpt, "set a global timeout on the command")
var OptionTimeout = cmdkit.StringOption(TimeoutOpt, "Set a global timeout on the command")
var OptionDerefArgs = cmdkit.BoolOption(DerefLong, "Symlinks supplied in arguments, are dereferenced")

0 comments on commit 9847a9f

Please sign in to comment.