From 9847a9fadb80ad02f4e88fa384aceed0bd71e990 Mon Sep 17 00:00:00 2001 From: Dominic Della Valle Date: Mon, 9 Apr 2018 10:29:29 -0400 Subject: [PATCH] Add support for dereferencing command-line arguments License: MIT Signed-off-by: Dominic Della Valle --- cli/parse.go | 9 +++++++-- opts.go | 6 ++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/cli/parse.go b/cli/parse.go index ccf59cdf..6ac33cdc 100644 --- a/cli/parse.go +++ b/cli/parse.go @@ -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" ) @@ -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 diff --git a/opts.go b/opts.go index ba953acf..66d1c21d 100644 --- a/opts.go +++ b/opts.go @@ -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")