提交 2b6b6fac 作者: Matt Bell 提交者: Juan Batiz-Benet

commands: Added a flag to enable stdin arguments

上级 9370740d
......@@ -8,11 +8,12 @@ const (
)
type Argument struct {
Name string
Type ArgumentType
Required bool
Variadic bool
Description string
Name string
Type ArgumentType
Required bool
Variadic bool
SupportsStdin bool
Description string
}
func StringArg(name string, required, variadic bool, description string) Argument {
......@@ -34,3 +35,8 @@ func FileArg(name string, required, variadic bool, description string) Argument
Description: description,
}
}
func (a Argument) EnableStdin() Argument {
a.SupportsStdin = true
return a
}
......@@ -171,7 +171,7 @@ func parseArgs(stringArgs []string, stdin *os.File, arguments []cmds.Argument) (
args = append(args, stringArgs[0])
stringArgs = stringArgs[1:]
} else {
} else if argDef.SupportsStdin {
// if we have a stdin, read it in and use the data as a string value
var buf bytes.Buffer
_, err := buf.ReadFrom(stdin)
......@@ -192,7 +192,7 @@ func parseArgs(stringArgs []string, stdin *os.File, arguments []cmds.Argument) (
args = append(args, file)
stringArgs = stringArgs[1:]
} else {
} else if argDef.SupportsStdin {
// if we have a stdin, use that as a reader
args = append(args, stdin)
stdin = nil
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论