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 ...@@ -70,7 +70,7 @@ func Parse(ctx context.Context, input []string, stdin *os.File, root *cmds.Comma
} }
func isHidden(req *cmds.Request) bool { func isHidden(req *cmds.Request) bool {
h, ok := req.Options["hidden"].(bool) h, ok := req.Options[cmds.Hidden].(bool)
return h && ok return h && ok
} }
...@@ -79,6 +79,11 @@ func isRecursive(req *cmds.Request) bool { ...@@ -79,6 +79,11 @@ func isRecursive(req *cmds.Request) bool {
return rec && ok return rec && ok
} }
func stdinName(req *cmds.Request) string {
name, _ := req.Options[cmds.StdinName].(string)
return name
}
type parseState struct { type parseState struct {
cmdline []string cmdline []string
i int i int
...@@ -265,7 +270,7 @@ func parseArgs(req *cmds.Request, root *cmds.Command, stdin *os.File) error { ...@@ -265,7 +270,7 @@ func parseArgs(req *cmds.Request, root *cmds.Command, stdin *os.File) error {
return err return err
} }
fpath = "" fpath = stdinName(req)
file, err = files.NewReaderPathFile(stdin.Name(), r, nil) file, err = files.NewReaderPathFile(stdin.Name(), r, nil)
if err != nil { if err != nil {
return err return err
...@@ -308,7 +313,7 @@ func parseArgs(req *cmds.Request, root *cmds.Command, stdin *os.File) error { ...@@ -308,7 +313,7 @@ func parseArgs(req *cmds.Request, root *cmds.Command, stdin *os.File) error {
return err return err
} }
fileArgs[""], err = files.NewReaderPathFile(stdin.Name(), r, nil) fileArgs[stdinName(req)], err = files.NewReaderPathFile(stdin.Name(), r, nil)
if err != nil { if err != nil {
return err return err
} }
......
...@@ -15,6 +15,9 @@ const ( ...@@ -15,6 +15,9 @@ const (
OptShortHelp = "h" OptShortHelp = "h"
OptLongHelp = "help" OptLongHelp = "help"
DerefLong = "dereference-args" DerefLong = "dereference-args"
StdinName = "stdin-name"
Hidden = "hidden"
HiddenShort = "H"
) )
// options that are used by this package // options that are used by this package
...@@ -23,3 +26,5 @@ var OptionRecursivePath = cmdkit.BoolOption(RecLong, RecShort, "Add directory pa ...@@ -23,3 +26,5 @@ var OptionRecursivePath = cmdkit.BoolOption(RecLong, RecShort, "Add directory pa
var OptionStreamChannels = cmdkit.BoolOption(ChanOpt, "Stream channel output") 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") 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