1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-08-06 11:31:54 +08:00

commands: Added a flag to enable stdin arguments

This commit is contained in:
Matt Bell
2014-11-14 02:22:58 -08:00
committed by Juan Batiz-Benet
parent 9370740db0
commit 2b6b6fac00
2 changed files with 13 additions and 7 deletions

View File

@ -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
}

View File

@ -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