request.go 806 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 {
5
	path			[]string
Matt Bell's avatar
Matt Bell committed
6 7
	options   map[string]interface{}
	arguments []string
Matt Bell's avatar
Matt Bell committed
8 9
}

10 11 12 13
func (r *Request) Path() []string {
	return r.path
}

14 15 16 17
func (r *Request) SetPath(path []string) {
	r.path = path
}

18
func (r *Request) Option(name string) interface{} {
Matt Bell's avatar
Matt Bell committed
19
	return r.options[name]
Matt Bell's avatar
Matt Bell committed
20 21
}

22
func (r *Request) SetOption(option Option, value interface{}) {
Matt Bell's avatar
Matt Bell committed
23 24 25 26 27
	// 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
	}
28 29
}

30
func (r *Request) Arguments() []string {
Matt Bell's avatar
Matt Bell committed
31
	return r.arguments
32
}
Matt Bell's avatar
Matt Bell committed
33 34

func NewRequest() *Request {
Matt Bell's avatar
Matt Bell committed
35
	return &Request{
36
		make([]string, 0),
Matt Bell's avatar
Matt Bell committed
37 38 39
		make(map[string]interface{}),
		make([]string, 0),
	}
Matt Bell's avatar
Matt Bell committed
40
}