From bbef82f4fa4a6821a614d56c98cbbbe4b424e49f Mon Sep 17 00:00:00 2001 From: Juan Batiz-Benet <juan@benet.ai> Date: Mon, 20 Oct 2014 07:59:39 -0700 Subject: [PATCH] "enc" -> EncShort --- commands/command_test.go | 4 ++-- commands/option.go | 8 +++++++- commands/response.go | 2 +- commands/response_test.go | 2 +- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/commands/command_test.go b/commands/command_test.go index 8e107bca..2f1601f4 100644 --- a/commands/command_test.go +++ b/commands/command_test.go @@ -57,7 +57,7 @@ func TestOptionValidation(t *testing.T) { } req = NewEmptyRequest() - req.options["enc"] = "json" + req.options[EncShort] = "json" res = cmd.Call(req) if res.Error != nil { t.Error("Should have passed") @@ -110,7 +110,7 @@ func TestRegistration(t *testing.T) { &Command{ Options: []Option{ - Option{[]string{"enc"}, String}, + Option{[]string{EncShort}, String}, }, run: func(req *Request, res *Response) {}, }, diff --git a/commands/option.go b/commands/option.go index d4faccec..8dbf3c1b 100644 --- a/commands/option.go +++ b/commands/option.go @@ -22,9 +22,15 @@ type Option struct { //Required bool // whether or not the option must be provided } +// Flag names +const ( + EncShort = "enc" + EncLong = "encoding" +) + // options that are used by this package var globalOptions = []Option{ - Option{[]string{"enc", "encoding"}, String}, + Option{[]string{EncShort, EncLong}, String}, } // the above array of Options, wrapped in a Command diff --git a/commands/response.go b/commands/response.go index f8847666..c9d1c5b9 100644 --- a/commands/response.go +++ b/commands/response.go @@ -66,7 +66,7 @@ func (r *Response) Marshal() ([]byte, error) { return nil, fmt.Errorf("No error or value set, there is nothing to marshal") } - enc, ok := r.req.Option("enc") + enc, ok := r.req.Option(EncShort) if !ok || enc.(string) == "" { return nil, fmt.Errorf("No encoding type was specified") } diff --git a/commands/response_test.go b/commands/response_test.go index 5ca31a37..432d78d6 100644 --- a/commands/response_test.go +++ b/commands/response_test.go @@ -30,7 +30,7 @@ func TestMarshalling(t *testing.T) { t.Error("Should have failed (no encoding type specified in request)") } - req.SetOption("enc", JSON) + req.SetOption(EncShort, JSON) req.convertOptions(options) bytes, err := res.Marshal() -- GitLab