cmd2 fixed config panic

The way the current marshallers marshal out output requires
a ton of error checking. I wish there was a way to have the
library call our marshaller with the right type (rather
than an interface). Maybe can do this with Reflect someday.
This commit is contained in:
Juan Batiz-Benet 2014-11-12 17:51:57 -08:00
parent f738e899c2
commit c46d4c8953

View File

@ -90,8 +90,17 @@ Set the value of the 'datastore.path' key:
return nil, nil // dont output anything
}
v := res.Output().(*ConfigField)
buf, err := config.HumanOutput(v.Value)
v := res.Output()
if v == nil {
k := res.Request().Arguments()[0]
return nil, fmt.Errorf("config does not contain key: %s", k)
}
vf, ok := v.(*ConfigField)
if !ok {
return nil, u.ErrCast()
}
buf, err := config.HumanOutput(vf.Value)
if err != nil {
return nil, err
}