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

commands: Changed Request#Arguments to a []string

This commit is contained in:
Matt Bell
2014-11-16 23:28:04 -08:00
parent 9dcf21673d
commit f8be26810a
4 changed files with 11 additions and 16 deletions

View File

@ -127,7 +127,7 @@ func parseOptions(input []string) (map[string]interface{}, []string, error) {
return opts, args, nil return opts, args, nil
} }
func parseArgs(inputs []string, stdin *os.File, argDefs []cmds.Argument, recursive bool) ([]interface{}, []cmds.File, error) { func parseArgs(inputs []string, stdin *os.File, argDefs []cmds.Argument, recursive bool) ([]string, []cmds.File, error) {
// check if stdin is coming from terminal or is being piped in // check if stdin is coming from terminal or is being piped in
if stdin != nil { if stdin != nil {
stat, err := stdin.Stat() stat, err := stdin.Stat()
@ -163,7 +163,7 @@ func parseArgs(inputs []string, stdin *os.File, argDefs []cmds.Argument, recursi
return nil, nil, fmt.Errorf("Expected %v arguments, got %v", len(argDefs), numInputs) return nil, nil, fmt.Errorf("Expected %v arguments, got %v", len(argDefs), numInputs)
} }
stringArgs := make([]interface{}, 0, numInputs) stringArgs := make([]string, 0, numInputs)
fileArgs := make([]cmds.File, 0, numInputs) fileArgs := make([]cmds.File, 0, numInputs)
argDefIndex := 0 // the index of the current argument definition argDefIndex := 0 // the index of the current argument definition

View File

@ -11,7 +11,6 @@ import (
cmds "github.com/jbenet/go-ipfs/commands" cmds "github.com/jbenet/go-ipfs/commands"
config "github.com/jbenet/go-ipfs/config" config "github.com/jbenet/go-ipfs/config"
u "github.com/jbenet/go-ipfs/util"
) )
const ( const (
@ -109,11 +108,7 @@ func getQuery(req cmds.Request) (string, error) {
} }
if argDef.Type == cmds.ArgString { if argDef.Type == cmds.ArgString {
str, ok := arg.(string) query.Add("arg", arg)
if !ok {
return "", u.ErrCast()
}
query.Add("arg", str)
} }
} }

View File

@ -51,7 +51,7 @@ func Parse(r *http.Request, root *cmds.Command) (cmds.Request, error) {
// count the number of provided argument values // count the number of provided argument values
valCount := len(stringArgs) valCount := len(stringArgs)
args := make([]interface{}, valCount) args := make([]string, valCount)
valIndex := 0 valIndex := 0
for _, argDef := range cmd.Arguments { for _, argDef := range cmd.Arguments {

View File

@ -61,8 +61,8 @@ type Request interface {
Option(name string) *OptionValue Option(name string) *OptionValue
Options() optMap Options() optMap
SetOption(name string, val interface{}) SetOption(name string, val interface{})
Arguments() []interface{} Arguments() []string
SetArguments([]interface{}) SetArguments([]string)
Files() File Files() File
SetFiles(File) SetFiles(File)
Context() *Context Context() *Context
@ -76,7 +76,7 @@ type Request interface {
type request struct { type request struct {
path []string path []string
options optMap options optMap
arguments []interface{} arguments []string
files File files File
cmd *Command cmd *Command
ctx Context ctx Context
@ -145,11 +145,11 @@ func (r *request) SetOption(name string, val interface{}) {
} }
// Arguments returns the arguments slice // Arguments returns the arguments slice
func (r *request) Arguments() []interface{} { func (r *request) Arguments() []string {
return r.arguments return r.arguments
} }
func (r *request) SetArguments(args []interface{}) { func (r *request) SetArguments(args []string) {
r.arguments = args r.arguments = args
} }
@ -258,7 +258,7 @@ func NewEmptyRequest() (Request, error) {
// NewRequest returns a request initialized with given arguments // NewRequest returns a request initialized with given arguments
// An non-nil error will be returned if the provided option values are invalid // An non-nil error will be returned if the provided option values are invalid
func NewRequest(path []string, opts optMap, args []interface{}, file File, cmd *Command, optDefs map[string]Option) (Request, error) { func NewRequest(path []string, opts optMap, args []string, file File, cmd *Command, optDefs map[string]Option) (Request, error) {
if path == nil { if path == nil {
path = make([]string, 0) path = make([]string, 0)
} }
@ -266,7 +266,7 @@ func NewRequest(path []string, opts optMap, args []interface{}, file File, cmd *
opts = make(map[string]interface{}) opts = make(map[string]interface{})
} }
if args == nil { if args == nil {
args = make([]interface{}, 0) args = make([]string, 0)
} }
if optDefs == nil { if optDefs == nil {
optDefs = make(map[string]Option) optDefs = make(map[string]Option)