"enc" -> EncShort
Juan Batiz-Benet committed
Oct 20, 2014 at 07:59 UTC
bbef82f4fa4a6821a614d56c98cbbbe4b424e49f
4 files changed
+11
-5
commands/command_test.go
+2
-2
@@ -57,7 +57,7 @@ func TestOptionValidation(t *testing.T) {
57
}
58
59
req = NewEmptyRequest()
60
- req.options["enc"] = "json"
60
+ req.options[EncShort] = "json"
61
res = cmd.Call(req)
62
if res.Error != nil {
63
t.Error("Should have passed")
@@ -110,7 +110,7 @@ func TestRegistration(t *testing.T) {
110
111
&Command{
112
Options: []Option{
113
- Option{[]string{"enc"}, String},
113
+ Option{[]string{EncShort}, String},
114
},
115
run: func(req *Request, res *Response) {},
116
},
commands/option.go
+7
-1
@@ -22,9 +22,15 @@ type Option struct {
22
//Required bool // whether or not the option must be provided
23
}
24
25
+// Flag names
26
+const (
27
+ EncShort = "enc"
28
+ EncLong = "encoding"
29
+)
30
+
31
// options that are used by this package
32
var globalOptions = []Option{
27
- Option{[]string{"enc", "encoding"}, String},
33
+ Option{[]string{EncShort, EncLong}, String},
34
}
35
36
// the above array of Options, wrapped in a Command
commands/response.go
+1
-1
@@ -66,7 +66,7 @@ func (r *Response) Marshal() ([]byte, error) {
66
return nil, fmt.Errorf("No error or value set, there is nothing to marshal")
67
}
68
69
- enc, ok := r.req.Option("enc")
69
+ enc, ok := r.req.Option(EncShort)
70
if !ok || enc.(string) == "" {
71
return nil, fmt.Errorf("No encoding type was specified")
72
}
commands/response_test.go
+1
-1
@@ -30,7 +30,7 @@ func TestMarshalling(t *testing.T) {
30
t.Error("Should have failed (no encoding type specified in request)")
31
}
32
33
- req.SetOption("enc", JSON)
33
+ req.SetOption(EncShort, JSON)
34
req.convertOptions(options)
35
36
bytes, err := res.Marshal()