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:

committed by
Juan Batiz-Benet

parent
9370740db0
commit
2b6b6fac00
@ -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
|
||||
|
Reference in New Issue
Block a user