mirror of
https://github.com/ipfs/kubo.git
synced 2025-08-06 03:19:47 +08:00

With verbose flag: * remove EnableStdin() flags on all StringArg, * remove all unneeded parsing code for StringArg, and print an * informative message if `ipfs` begins reading from a CharDevice, * remove broken go tests for EnableStdin cli parsing, and add some * trivial test cases for reading FileArg from stdin, * add a panic to prevent EnableStdin from being set on * StringArg in the future. Resolves: #2877, #2870 License: MIT Signed-off-by: Thomas Gardner <tmg@fastmail.com>
60 lines
1.3 KiB
Go
60 lines
1.3 KiB
Go
package commands
|
|
|
|
type ArgumentType int
|
|
|
|
const (
|
|
ArgString ArgumentType = iota
|
|
ArgFile
|
|
)
|
|
|
|
type Argument struct {
|
|
Name string
|
|
Type ArgumentType
|
|
Required bool // error if no value is specified
|
|
Variadic bool // unlimited values can be specfied
|
|
SupportsStdin bool // can accept stdin as a value
|
|
Recursive bool // supports recursive file adding (with '-r' flag)
|
|
Description string
|
|
}
|
|
|
|
func StringArg(name string, required, variadic bool, description string) Argument {
|
|
return Argument{
|
|
Name: name,
|
|
Type: ArgString,
|
|
Required: required,
|
|
Variadic: variadic,
|
|
Description: description,
|
|
}
|
|
}
|
|
|
|
func FileArg(name string, required, variadic bool, description string) Argument {
|
|
return Argument{
|
|
Name: name,
|
|
Type: ArgFile,
|
|
Required: required,
|
|
Variadic: variadic,
|
|
Description: description,
|
|
}
|
|
}
|
|
|
|
// TODO: modifiers might need a different API?
|
|
// e.g. passing enum values into arg constructors variadically
|
|
// (`FileArg("file", ArgRequired, ArgStdin, ArgRecursive)`)
|
|
|
|
func (a Argument) EnableStdin() Argument {
|
|
if a.Type == ArgString {
|
|
panic("Only FileArgs can be read from Stdin")
|
|
}
|
|
a.SupportsStdin = true
|
|
return a
|
|
}
|
|
|
|
func (a Argument) EnableRecursive() Argument {
|
|
if a.Type != ArgFile {
|
|
panic("Only FileArgs can enable recursive")
|
|
}
|
|
|
|
a.Recursive = true
|
|
return a
|
|
}
|