Commit 8a4e361a authored by Steven Allen's avatar Steven Allen

chore: remove some dead code

parent 746d639b
......@@ -180,97 +180,3 @@ func FloatOption(names ...string) Option {
func StringOption(names ...string) Option {
return NewOption(String, names...)
}
type OptionValue struct {
Value interface{}
ValueFound bool
Def Option
}
// Found returns true if the option value was provided by the user (not a default value)
func (ov *OptionValue) Found() bool {
return ov.ValueFound
}
// Definition returns the option definition for the provided value
func (ov *OptionValue) Definition() Option {
return ov.Def
}
// value accessor methods, gets the value as a certain type
func (ov *OptionValue) Bool() (value bool, found bool, err error) {
if ov == nil || !ov.ValueFound && ov.Value == nil {
return false, false, nil
}
val, ok := ov.Value.(bool)
if !ok {
err = fmt.Errorf("expected type %T, got %T", val, ov.Value)
}
return val, ov.ValueFound, err
}
func (ov *OptionValue) Int() (value int, found bool, err error) {
if ov == nil || !ov.ValueFound && ov.Value == nil {
return 0, false, nil
}
val, ok := ov.Value.(int)
if !ok {
err = fmt.Errorf("expected type %T, got %T", val, ov.Value)
}
return val, ov.ValueFound, err
}
func (ov *OptionValue) Uint() (value uint, found bool, err error) {
if ov == nil || !ov.ValueFound && ov.Value == nil {
return 0, false, nil
}
val, ok := ov.Value.(uint)
if !ok {
err = fmt.Errorf("expected type %T, got %T", val, ov.Value)
}
return val, ov.ValueFound, err
}
func (ov *OptionValue) Int64() (value int64, found bool, err error) {
if ov == nil || !ov.ValueFound && ov.Value == nil {
return 0, false, nil
}
val, ok := ov.Value.(int64)
if !ok {
err = fmt.Errorf("expected type %T, got %T", val, ov.Value)
}
return val, ov.ValueFound, err
}
func (ov *OptionValue) Uint64() (value uint64, found bool, err error) {
if ov == nil || !ov.ValueFound && ov.Value == nil {
return 0, false, nil
}
val, ok := ov.Value.(uint64)
if !ok {
err = fmt.Errorf("expected type %T, got %T", val, ov.Value)
}
return val, ov.ValueFound, err
}
func (ov *OptionValue) Float() (value float64, found bool, err error) {
if ov == nil || !ov.ValueFound && ov.Value == nil {
return 0, false, nil
}
val, ok := ov.Value.(float64)
if !ok {
err = fmt.Errorf("expected type %T, got %T", val, ov.Value)
}
return val, ov.ValueFound, err
}
func (ov *OptionValue) String() (value string, found bool, err error) {
if ov == nil || !ov.ValueFound && ov.Value == nil {
return "", false, nil
}
val, ok := ov.Value.(string)
if !ok {
err = fmt.Errorf("expected type %T, got %T", val, ov.Value)
}
return val, ov.ValueFound, err
}
......@@ -7,32 +7,6 @@ import (
"testing"
)
func TestOptionValueExtractBoolNotFound(t *testing.T) {
t.Log("ensure that no error is returned when value is not found")
optval := &OptionValue{ValueFound: false}
_, _, err := optval.Bool()
if err != nil {
t.Fatal("Found was false. Err should have been nil")
}
}
func TestOptionValueExtractWrongType(t *testing.T) {
t.Log("ensure that error is returned when value if of wrong type")
optval := &OptionValue{Value: "wrong type: a string", ValueFound: true}
_, _, err := optval.Bool()
if err == nil {
t.Fatal("No error returned. Failure.")
}
optval = &OptionValue{Value: "wrong type: a string", ValueFound: true}
_, _, err = optval.Int()
if err == nil {
t.Fatal("No error returned. Failure.")
}
}
func TestLackOfDescriptionOfOptionDoesNotPanic(t *testing.T) {
opt := BoolOption("a", "")
opt.Description()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment