Unverified Commit 49cf8cee authored by Steven Allen's avatar Steven Allen Committed by GitHub

Merge pull request #157 from ipfs/feat/stdin-name

Handle stdin name in cli/parse
parents 4ca651ae a55e1114
......@@ -70,7 +70,7 @@ func Parse(ctx context.Context, input []string, stdin *os.File, root *cmds.Comma
}
func isHidden(req *cmds.Request) bool {
h, ok := req.Options["hidden"].(bool)
h, ok := req.Options[cmds.Hidden].(bool)
return h && ok
}
......@@ -79,6 +79,11 @@ func isRecursive(req *cmds.Request) bool {
return rec && ok
}
func stdinName(req *cmds.Request) string {
name, _ := req.Options[cmds.StdinName].(string)
return name
}
type parseState struct {
cmdline []string
i int
......@@ -265,7 +270,7 @@ func parseArgs(req *cmds.Request, root *cmds.Command, stdin *os.File) error {
return err
}
fpath = ""
fpath = stdinName(req)
file, err = files.NewReaderPathFile(stdin.Name(), r, nil)
if err != nil {
return err
......@@ -308,7 +313,7 @@ func parseArgs(req *cmds.Request, root *cmds.Command, stdin *os.File) error {
return err
}
fileArgs[""], err = files.NewReaderPathFile(stdin.Name(), r, nil)
fileArgs[stdinName(req)], err = files.NewReaderPathFile(stdin.Name(), r, nil)
if err != nil {
return err
}
......
......@@ -15,6 +15,9 @@ const (
OptShortHelp = "h"
OptLongHelp = "help"
DerefLong = "dereference-args"
StdinName = "stdin-name"
Hidden = "hidden"
HiddenShort = "H"
)
// options that are used by this package
......@@ -23,3 +26,5 @@ var OptionRecursivePath = cmdkit.BoolOption(RecLong, RecShort, "Add directory pa
var OptionStreamChannels = cmdkit.BoolOption(ChanOpt, "Stream channel output")
var OptionTimeout = cmdkit.StringOption(TimeoutOpt, "Set a global timeout on the command")
var OptionDerefArgs = cmdkit.BoolOption(DerefLong, "Symlinks supplied in arguments are dereferenced")
var OptionStdinName = cmdkit.StringOption(StdinName, "Assign a name if the file source is stdin.")
var OptionHidden = cmdkit.BoolOption(Hidden, HiddenShort, "Include files that are hidden. Only takes effect on recursive add.")
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment