request.go 653 Bytes
Newer Older
Matt Bell's avatar
Matt Bell committed
1 2 3 4
package commands

// Request represents a call to a command from a consumer
type Request struct {
Matt Bell's avatar
Matt Bell committed
5 6
	options   map[string]interface{}
	arguments []string
Matt Bell's avatar
Matt Bell committed
7 8
}

9
func (r *Request) Option(name string) interface{} {
Matt Bell's avatar
Matt Bell committed
10
	return r.options[name]
Matt Bell's avatar
Matt Bell committed
11 12
}

13
func (r *Request) SetOption(option Option, value interface{}) {
Matt Bell's avatar
Matt Bell committed
14 15 16 17 18
	// saves the option value in the map, indexed by each name
	// (so commands can retrieve it using any of the names)
	for _, name := range option.Names {
		r.options[name] = value
	}
19 20
}

21
func (r *Request) Arguments() []string {
Matt Bell's avatar
Matt Bell committed
22
	return r.arguments
23
}
Matt Bell's avatar
Matt Bell committed
24 25

func NewRequest() *Request {
Matt Bell's avatar
Matt Bell committed
26 27 28 29
	return &Request{
		make(map[string]interface{}),
		make([]string, 0),
	}
Matt Bell's avatar
Matt Bell committed
30
}