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 <ddvpublic@gmail.com>
  • Loading branch information
djdv committed Sep 19, 2018
1 parent 6aaaa76 commit c71d230
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
15 changes: 13 additions & 2 deletions cli/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ 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-cmdkit/files"
"github.com/ipfs/go-ipfs-cmds"
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
1 change: 1 addition & 0 deletions cli/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io"
"io/ioutil"
"os"
"path/filepath"
"runtime"
"strings"
"testing"
Expand Down
4 changes: 3 additions & 1 deletion 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 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 symlinks instead of adding them as-is").WithDefault(false)

0 comments on commit c71d230

Please sign in to comment.