commands: Changed Request#Arguments to a []string
Matt Bell committed
Nov 16, 2014 at 23:28 UTC
f8be26810ae1359f10f263b461d8bdba61daf56e
4 files changed
+11
-16
commands/cli/parse.go
+2
-2
@@ -127,7 +127,7 @@ func parseOptions(input []string) (map[string]interface{}, []string, error) {
127
return opts, args, nil
128
}
129
130
-func parseArgs(inputs []string, stdin *os.File, argDefs []cmds.Argument, recursive bool) ([]interface{}, []cmds.File, error) {
130
+func parseArgs(inputs []string, stdin *os.File, argDefs []cmds.Argument, recursive bool) ([]string, []cmds.File, error) {
131
// check if stdin is coming from terminal or is being piped in
132
if stdin != nil {
133
stat, err := stdin.Stat()
@@ -163,7 +163,7 @@ func parseArgs(inputs []string, stdin *os.File, argDefs []cmds.Argument, recursi
163
return nil, nil, fmt.Errorf("Expected %v arguments, got %v", len(argDefs), numInputs)
164
}
165
166
- stringArgs := make([]interface{}, 0, numInputs)
166
+ stringArgs := make([]string, 0, numInputs)
167
fileArgs := make([]cmds.File, 0, numInputs)
168
169
argDefIndex := 0 // the index of the current argument definition
commands/http/client.go
+1
-6
@@ -11,7 +11,6 @@ import (
11
12
cmds "github.com/jbenet/go-ipfs/commands"
13
config "github.com/jbenet/go-ipfs/config"
14
- u "github.com/jbenet/go-ipfs/util"
14
)
15
16
const (
@@ -109,11 +108,7 @@ func getQuery(req cmds.Request) (string, error) {
108
}
109
110
if argDef.Type == cmds.ArgString {
112
- str, ok := arg.(string)
113
- if !ok {
114
- return "", u.ErrCast()
115
- }
116
- query.Add("arg", str)
111
+ query.Add("arg", arg)
112
}
113
}
114
commands/http/parse.go
+1
-1
@@ -51,7 +51,7 @@ func Parse(r *http.Request, root *cmds.Command) (cmds.Request, error) {
51
// count the number of provided argument values
52
valCount := len(stringArgs)
53
54
- args := make([]interface{}, valCount)
54
+ args := make([]string, valCount)
55
56
valIndex := 0
57
for _, argDef := range cmd.Arguments {
commands/request.go
+7
-7
@@ -61,8 +61,8 @@ type Request interface {
61
Option(name string) *OptionValue
62
Options() optMap
63
SetOption(name string, val interface{})
64
- Arguments() []interface{}
65
- SetArguments([]interface{})
64
+ Arguments() []string
65
+ SetArguments([]string)
66
Files() File
67
SetFiles(File)
68
Context() *Context
@@ -76,7 +76,7 @@ type Request interface {
76
type request struct {
77
path []string
78
options optMap
79
- arguments []interface{}
79
+ arguments []string
80
files File
81
cmd *Command
82
ctx Context
@@ -145,11 +145,11 @@ func (r *request) SetOption(name string, val interface{}) {
145
}
146
147
// Arguments returns the arguments slice
148
-func (r *request) Arguments() []interface{} {
148
+func (r *request) Arguments() []string {
149
return r.arguments
150
}
151
152
-func (r *request) SetArguments(args []interface{}) {
152
+func (r *request) SetArguments(args []string) {
153
r.arguments = args
154
}
155
@@ -258,7 +258,7 @@ func NewEmptyRequest() (Request, error) {
258
259
// NewRequest returns a request initialized with given arguments
260
// An non-nil error will be returned if the provided option values are invalid
261
-func NewRequest(path []string, opts optMap, args []interface{}, file File, cmd *Command, optDefs map[string]Option) (Request, error) {
261
+func NewRequest(path []string, opts optMap, args []string, file File, cmd *Command, optDefs map[string]Option) (Request, error) {
262
if path == nil {
263
path = make([]string, 0)
264
}
@@ -266,7 +266,7 @@ func NewRequest(path []string, opts optMap, args []interface{}, file File, cmd *
266
opts = make(map[string]interface{})
267
}
268
if args == nil {
269
- args = make([]interface{}, 0)
269
+ args = make([]string, 0)
270
}
271
if optDefs == nil {
272
optDefs = make(map[string]Option)