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 28, 2018
1 parent adc3f9b commit 8923429
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
15 changes: 13 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 @@ -79,6 +78,11 @@ func isRecursive(req *cmds.Request) bool {
return rec && ok
}

func resolveCommandLine(req *cmds.Request) bool {
linkOpt, ok := req.Options[cmds.DerefLong].(bool)
return linkOpt && ok
}

type parseState struct {
cmdline []string
i int
Expand Down Expand Up @@ -265,6 +269,13 @@ func parseArgs(req *cmds.Request, root *cmds.Command, stdin *os.File) error {
fpath = stdin.Name()
file = files.NewReaderFile("", fpath, r, nil)
} else {
if resolveCommandLine(req) {
var err error
fpath, err = filepath.EvalSymlinks(fpath)
if 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, "Resolve link arguments, instead of adding links as links")

0 comments on commit 8923429

Please sign in to comment.