@cryptotaxi247 / kubo / commits / 1c8d73f9e

commands: Added Request#Files()

Matt Bell committed Nov 16, 2014 at 00:44 UTC 1c8d73f9ea4360e1d055dad7276a89ae24c5ba00
1 file changed +11 -21
commands/request.go
+11 -21
@@ -3,7 +3,6 @@ package commands
3 import (
4 "errors"
5 "fmt"
6 - "io"
6 "reflect"
7 "strconv"
8
@@ -62,13 +61,8 @@ type Request interface {
61 Option(name string) *OptionValue
62 Options() optMap
63 SetOption(name string, val interface{})
65 -
66 - // Arguments() returns user provided arguments as declared on the Command.
67 - //
68 - // NB: `io.Reader`s returned by Arguments() are owned by the library.
69 - // Readers are not guaranteed to remain open after the Command's Run
70 - // function returns.
71 - Arguments() []interface{} // TODO: make argument value type instead of using interface{}
64 + Arguments() []interface{}
65 + Files() File
66 Context() *Context
67 SetContext(Context)
68 Command() *Command
@@ -81,6 +75,7 @@ type request struct {
75 path []string
76 options optMap
77 arguments []interface{}
78 + files File
79 cmd *Command
80 ctx Context
81 optionDefs map[string]Option
@@ -152,6 +147,10 @@ func (r *request) Arguments() []interface{} {
147 return r.arguments
148 }
149
150 +func (r *request) Files() File {
151 + return r.files
152 +}
153 +
154 func (r *request) Context() *Context {
155 return &r.ctx
156 }
@@ -165,16 +164,7 @@ func (r *request) Command() *Command {
164 }
165
166 func (r *request) Cleanup() error {
168 - for _, arg := range r.arguments {
169 - closer, ok := arg.(io.Closer)
170 - if ok {
171 - err := closer.Close()
172 - if err != nil {
173 - return err
174 - }
175 - }
176 - }
177 -
167 + // TODO
168 return nil
169 }
170
@@ -253,12 +243,12 @@ func (r *request) ConvertOptions() error {
243
244 // NewEmptyRequest initializes an empty request
245 func NewEmptyRequest() (Request, error) {
256 - return NewRequest(nil, nil, nil, nil, nil)
246 + return NewRequest(nil, nil, nil, nil, nil, nil)
247 }
248
249 // NewRequest returns a request initialized with given arguments
250 // An non-nil error will be returned if the provided option values are invalid
261 -func NewRequest(path []string, opts optMap, args []interface{}, cmd *Command, optDefs map[string]Option) (Request, error) {
251 +func NewRequest(path []string, opts optMap, args []interface{}, file File, cmd *Command, optDefs map[string]Option) (Request, error) {
252 if path == nil {
253 path = make([]string, 0)
254 }
@@ -272,7 +262,7 @@ func NewRequest(path []string, opts optMap, args []interface{}, cmd *Command, op
262 optDefs = make(map[string]Option)
263 }
264
275 - req := &request{path, opts, args, cmd, Context{}, optDefs}
265 + req := &request{path, opts, args, file, cmd, Context{}, optDefs}
266 err := req.ConvertOptions()
267 if err != nil {
268 return nil, err