Commit 1c8d73f9 authored by Matt Bell's avatar Matt Bell

commands: Added Request#Files()

parent fdb71eb5
...@@ -3,7 +3,6 @@ package commands ...@@ -3,7 +3,6 @@ package commands
import ( import (
"errors" "errors"
"fmt" "fmt"
"io"
"reflect" "reflect"
"strconv" "strconv"
...@@ -62,13 +61,8 @@ type Request interface { ...@@ -62,13 +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() returns user provided arguments as declared on the Command. Files() File
//
// NB: `io.Reader`s returned by Arguments() are owned by the library.
// Readers are not guaranteed to remain open after the Command's Run
// function returns.
Arguments() []interface{} // TODO: make argument value type instead of using interface{}
Context() *Context Context() *Context
SetContext(Context) SetContext(Context)
Command() *Command Command() *Command
...@@ -81,6 +75,7 @@ type request struct { ...@@ -81,6 +75,7 @@ type request struct {
path []string path []string
options optMap options optMap
arguments []interface{} arguments []interface{}
files File
cmd *Command cmd *Command
ctx Context ctx Context
optionDefs map[string]Option optionDefs map[string]Option
...@@ -152,6 +147,10 @@ func (r *request) Arguments() []interface{} { ...@@ -152,6 +147,10 @@ func (r *request) Arguments() []interface{} {
return r.arguments return r.arguments
} }
func (r *request) Files() File {
return r.files
}
func (r *request) Context() *Context { func (r *request) Context() *Context {
return &r.ctx return &r.ctx
} }
...@@ -165,16 +164,7 @@ func (r *request) Command() *Command { ...@@ -165,16 +164,7 @@ func (r *request) Command() *Command {
} }
func (r *request) Cleanup() error { func (r *request) Cleanup() error {
for _, arg := range r.arguments { // TODO
closer, ok := arg.(io.Closer)
if ok {
err := closer.Close()
if err != nil {
return err
}
}
}
return nil return nil
} }
...@@ -253,12 +243,12 @@ func (r *request) ConvertOptions() error { ...@@ -253,12 +243,12 @@ func (r *request) ConvertOptions() error {
// NewEmptyRequest initializes an empty request // NewEmptyRequest initializes an empty request
func NewEmptyRequest() (Request, error) { func NewEmptyRequest() (Request, error) {
return NewRequest(nil, nil, nil, nil, nil) return NewRequest(nil, nil, nil, nil, nil, nil)
} }
// 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{}, cmd *Command, optDefs map[string]Option) (Request, error) { func NewRequest(path []string, opts optMap, args []interface{}, file File, cmd *Command, optDefs map[string]Option) (Request, error) {
if path == nil { if path == nil {
path = make([]string, 0) path = make([]string, 0)
} }
...@@ -272,7 +262,7 @@ func NewRequest(path []string, opts optMap, args []interface{}, cmd *Command, op ...@@ -272,7 +262,7 @@ func NewRequest(path []string, opts optMap, args []interface{}, cmd *Command, op
optDefs = make(map[string]Option) optDefs = make(map[string]Option)
} }
req := &request{path, opts, args, cmd, Context{}, optDefs} req := &request{path, opts, args, file, cmd, Context{}, optDefs}
err := req.ConvertOptions() err := req.ConvertOptions()
if err != nil { if err != nil {
return nil, err return nil, err
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment