Skip to content

Commit 8a4e361

Browse files
committed
chore: remove some dead code
1 parent 746d639 commit 8a4e361

File tree

2 files changed

+0
-120
lines changed

2 files changed

+0
-120
lines changed

option.go

-94
Original file line numberDiff line numberDiff line change
@@ -180,97 +180,3 @@ func FloatOption(names ...string) Option {
180180
func StringOption(names ...string) Option {
181181
return NewOption(String, names...)
182182
}
183-
184-
type OptionValue struct {
185-
Value interface{}
186-
ValueFound bool
187-
Def Option
188-
}
189-
190-
// Found returns true if the option value was provided by the user (not a default value)
191-
func (ov *OptionValue) Found() bool {
192-
return ov.ValueFound
193-
}
194-
195-
// Definition returns the option definition for the provided value
196-
func (ov *OptionValue) Definition() Option {
197-
return ov.Def
198-
}
199-
200-
// value accessor methods, gets the value as a certain type
201-
func (ov *OptionValue) Bool() (value bool, found bool, err error) {
202-
if ov == nil || !ov.ValueFound && ov.Value == nil {
203-
return false, false, nil
204-
}
205-
val, ok := ov.Value.(bool)
206-
if !ok {
207-
err = fmt.Errorf("expected type %T, got %T", val, ov.Value)
208-
}
209-
return val, ov.ValueFound, err
210-
}
211-
212-
func (ov *OptionValue) Int() (value int, found bool, err error) {
213-
if ov == nil || !ov.ValueFound && ov.Value == nil {
214-
return 0, false, nil
215-
}
216-
val, ok := ov.Value.(int)
217-
if !ok {
218-
err = fmt.Errorf("expected type %T, got %T", val, ov.Value)
219-
}
220-
return val, ov.ValueFound, err
221-
}
222-
223-
func (ov *OptionValue) Uint() (value uint, found bool, err error) {
224-
if ov == nil || !ov.ValueFound && ov.Value == nil {
225-
return 0, false, nil
226-
}
227-
val, ok := ov.Value.(uint)
228-
if !ok {
229-
err = fmt.Errorf("expected type %T, got %T", val, ov.Value)
230-
}
231-
return val, ov.ValueFound, err
232-
}
233-
234-
func (ov *OptionValue) Int64() (value int64, found bool, err error) {
235-
if ov == nil || !ov.ValueFound && ov.Value == nil {
236-
return 0, false, nil
237-
}
238-
val, ok := ov.Value.(int64)
239-
if !ok {
240-
err = fmt.Errorf("expected type %T, got %T", val, ov.Value)
241-
}
242-
return val, ov.ValueFound, err
243-
}
244-
245-
func (ov *OptionValue) Uint64() (value uint64, found bool, err error) {
246-
if ov == nil || !ov.ValueFound && ov.Value == nil {
247-
return 0, false, nil
248-
}
249-
val, ok := ov.Value.(uint64)
250-
if !ok {
251-
err = fmt.Errorf("expected type %T, got %T", val, ov.Value)
252-
}
253-
return val, ov.ValueFound, err
254-
}
255-
256-
func (ov *OptionValue) Float() (value float64, found bool, err error) {
257-
if ov == nil || !ov.ValueFound && ov.Value == nil {
258-
return 0, false, nil
259-
}
260-
val, ok := ov.Value.(float64)
261-
if !ok {
262-
err = fmt.Errorf("expected type %T, got %T", val, ov.Value)
263-
}
264-
return val, ov.ValueFound, err
265-
}
266-
267-
func (ov *OptionValue) String() (value string, found bool, err error) {
268-
if ov == nil || !ov.ValueFound && ov.Value == nil {
269-
return "", false, nil
270-
}
271-
val, ok := ov.Value.(string)
272-
if !ok {
273-
err = fmt.Errorf("expected type %T, got %T", val, ov.Value)
274-
}
275-
return val, ov.ValueFound, err
276-
}

option_test.go

-26
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,6 @@ import (
77
"testing"
88
)
99

10-
func TestOptionValueExtractBoolNotFound(t *testing.T) {
11-
t.Log("ensure that no error is returned when value is not found")
12-
optval := &OptionValue{ValueFound: false}
13-
_, _, err := optval.Bool()
14-
if err != nil {
15-
t.Fatal("Found was false. Err should have been nil")
16-
}
17-
}
18-
19-
func TestOptionValueExtractWrongType(t *testing.T) {
20-
21-
t.Log("ensure that error is returned when value if of wrong type")
22-
23-
optval := &OptionValue{Value: "wrong type: a string", ValueFound: true}
24-
_, _, err := optval.Bool()
25-
if err == nil {
26-
t.Fatal("No error returned. Failure.")
27-
}
28-
29-
optval = &OptionValue{Value: "wrong type: a string", ValueFound: true}
30-
_, _, err = optval.Int()
31-
if err == nil {
32-
t.Fatal("No error returned. Failure.")
33-
}
34-
}
35-
3610
func TestLackOfDescriptionOfOptionDoesNotPanic(t *testing.T) {
3711
opt := BoolOption("a", "")
3812
opt.Description()

0 commit comments

Comments
 (0)