Commit c0b28dc1 authored by Matt Bell's avatar Matt Bell

commands: Added input stream field to Request

parent b10fc2cc
...@@ -4,6 +4,7 @@ import ( ...@@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"reflect" "reflect"
"strconv" "strconv"
"io"
) )
type optMap map[string]interface{} type optMap map[string]interface{}
...@@ -14,6 +15,7 @@ type Request interface { ...@@ -14,6 +15,7 @@ type Request interface {
Option(name string) (interface{}, bool) Option(name string) (interface{}, bool)
SetOption(name string, val interface{}) SetOption(name string, val interface{})
Arguments() []string Arguments() []string
Stream() io.Reader
ConvertOptions(options map[string]Option) error ConvertOptions(options map[string]Option) error
} }
...@@ -22,6 +24,7 @@ type request struct { ...@@ -22,6 +24,7 @@ type request struct {
path []string path []string
options optMap options optMap
arguments []string arguments []string
in io.Reader
} }
// Path returns the command path of this request // Path returns the command path of this request
...@@ -45,6 +48,11 @@ func (r *request) Arguments() []string { ...@@ -45,6 +48,11 @@ func (r *request) Arguments() []string {
return r.arguments return r.arguments
} }
// Stream returns the input stream Reader
func (r *request) Stream() io.Reader {
return r.in
}
type converter func(string) (interface{}, error) type converter func(string) (interface{}, error)
var converters = map[reflect.Kind]converter{ var converters = map[reflect.Kind]converter{
...@@ -111,11 +119,11 @@ func (r *request) ConvertOptions(options map[string]Option) error { ...@@ -111,11 +119,11 @@ func (r *request) ConvertOptions(options map[string]Option) error {
// NewEmptyRequest initializes an empty request // NewEmptyRequest initializes an empty request
func NewEmptyRequest() Request { func NewEmptyRequest() Request {
return NewRequest(nil, nil, nil) return NewRequest(nil, nil, nil, nil)
} }
// NewRequest returns a request initialized with given arguments // NewRequest returns a request initialized with given arguments
func NewRequest(path []string, opts optMap, args []string) Request { func NewRequest(path []string, opts optMap, args []string, in io.Reader) Request {
if path == nil { if path == nil {
path = make([]string, 0) path = make([]string, 0)
} }
...@@ -125,5 +133,5 @@ func NewRequest(path []string, opts optMap, args []string) Request { ...@@ -125,5 +133,5 @@ func NewRequest(path []string, opts optMap, args []string) Request {
if args == nil { if args == nil {
args = make([]string, 0) args = make([]string, 0)
} }
return &request{path, opts, args} return &request{path, opts, args, in}
} }
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