Commit c01c951a authored by Matt Bell's avatar Matt Bell Committed by Juan Batiz-Benet

commands: Added a flag to enable stdin arguments

parent 4567e0f1
......@@ -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 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