mirror of
https://github.com/ipfs/kubo.git
synced 2025-09-10 14:34:24 +08:00
Merge pull request #2288 from tomgg/tmg/trivial
trivial: various superficial fixes
This commit is contained in:
@ -133,7 +133,8 @@ func (c *Command) Call(req Request) Response {
|
||||
}
|
||||
}
|
||||
|
||||
// If the command specified an output type, ensure the actual value returned is of that type
|
||||
// If the command specified an output type, ensure the actual value
|
||||
// returned is of that type
|
||||
if cmd.Type != nil && !isChan {
|
||||
expectedType := reflect.TypeOf(cmd.Type)
|
||||
|
||||
@ -146,7 +147,7 @@ func (c *Command) Call(req Request) Response {
|
||||
return res
|
||||
}
|
||||
|
||||
// Resolve gets the subcommands at the given path
|
||||
// Resolve returns the subcommands at the given path
|
||||
func (c *Command) Resolve(pth []string) ([]*Command, error) {
|
||||
cmds := make([]*Command, len(pth)+1)
|
||||
cmds[0] = c
|
||||
@ -175,7 +176,7 @@ func (c *Command) Get(path []string) (*Command, error) {
|
||||
return cmds[len(cmds)-1], nil
|
||||
}
|
||||
|
||||
// GetOptions gets the options in the given path of commands
|
||||
// GetOptions returns the options in the given path of commands
|
||||
func (c *Command) GetOptions(path []string) (map[string]Option, error) {
|
||||
options := make([]Option, 0, len(c.Options))
|
||||
|
||||
@ -217,12 +218,15 @@ func (c *Command) CheckArguments(req Request) error {
|
||||
// iterate over the arg definitions
|
||||
valueIndex := 0 // the index of the current value (in `args`)
|
||||
for _, argDef := range c.Arguments {
|
||||
// skip optional argument definitions if there aren't sufficient remaining values
|
||||
if len(args)-valueIndex <= numRequired && !argDef.Required || argDef.Type == ArgFile {
|
||||
// skip optional argument definitions if there aren't
|
||||
// sufficient remaining values
|
||||
if len(args)-valueIndex <= numRequired && !argDef.Required ||
|
||||
argDef.Type == ArgFile {
|
||||
continue
|
||||
}
|
||||
|
||||
// the value for this argument definition. can be nil if it wasn't provided by the caller
|
||||
// the value for this argument definition. can be nil if it
|
||||
// wasn't provided by the caller
|
||||
v, found := "", false
|
||||
if valueIndex < len(args) {
|
||||
v = args[valueIndex]
|
||||
@ -254,7 +258,8 @@ func (c *Command) Subcommand(id string) *Command {
|
||||
return c.Subcommands[id]
|
||||
}
|
||||
|
||||
// checkArgValue returns an error if a given arg value is not valid for the given Argument
|
||||
// checkArgValue returns an error if a given arg value is not valid for the
|
||||
// given Argument
|
||||
func checkArgValue(v string, found bool, def Argument) error {
|
||||
if !found && def.Required {
|
||||
return fmt.Errorf("Argument '%s' is required", def.Name)
|
||||
|
@ -11,11 +11,12 @@ var (
|
||||
ErrNotReader = errors.New("This file is a directory, can't use Reader functions")
|
||||
)
|
||||
|
||||
// File is an interface that provides functionality for handling files/directories
|
||||
// as values that can be supplied to commands. For directories, child files are
|
||||
// accessed serially by calling `NextFile()`.
|
||||
// File is an interface that provides functionality for handling
|
||||
// files/directories as values that can be supplied to commands. For
|
||||
// directories, child files are accessed serially by calling `NextFile()`.
|
||||
type File interface {
|
||||
// Files implement ReadCloser, but can only be read from or closed if they are not directories
|
||||
// Files implement ReadCloser, but can only be read from or closed if
|
||||
// they are not directories
|
||||
io.ReadCloser
|
||||
|
||||
// FileName returns a filename path associated with this file
|
||||
@ -24,13 +25,15 @@ type File interface {
|
||||
// FullPath returns the full path in the os associated with this file
|
||||
FullPath() string
|
||||
|
||||
// IsDirectory returns true if the File is a directory (and therefore supports calling `NextFile`)
|
||||
// and false if the File is a normal file (and therefor supports calling `Read` and `Close`)
|
||||
// IsDirectory returns true if the File is a directory (and therefore
|
||||
// supports calling `NextFile`) and false if the File is a normal file
|
||||
// (and therefor supports calling `Read` and `Close`)
|
||||
IsDirectory() bool
|
||||
|
||||
// NextFile returns the next child file available (if the File is a directory).
|
||||
// It will return (nil, io.EOF) if no more files are available.
|
||||
// If the file is a regular file (not a directory), NextFile will return a non-nil error.
|
||||
// NextFile returns the next child file available (if the File is a
|
||||
// directory). It will return (nil, io.EOF) if no more files are
|
||||
// available. If the file is a regular file (not a directory), NextFile
|
||||
// will return a non-nil error.
|
||||
NextFile() (File, error)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user