Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3-cmds
Commits
8a4e361a
Commit
8a4e361a
authored
May 10, 2019
by
Steven Allen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: remove some dead code
parent
746d639b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
0 additions
and
120 deletions
+0
-120
option.go
option.go
+0
-94
option_test.go
option_test.go
+0
-26
No files found.
option.go
View file @
8a4e361a
...
...
@@ -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
}
option_test.go
View file @
8a4e361a
...
...
@@ -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
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment