1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-08-06 03:19:47 +08:00

"enc" -> EncShort

This commit is contained in:
Juan Batiz-Benet
2014-10-20 07:59:39 -07:00
parent 4986600e54
commit bbef82f4fa
4 changed files with 11 additions and 5 deletions

View File

@ -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) {},
},

View File

@ -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

View File

@ -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")
}

View File

@ -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()