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
6f79696e
Commit
6f79696e
authored
Nov 10, 2014
by
Matt Bell
Committed by
Juan Batiz-Benet
Nov 14, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commands: Fixed handling of int/uint option values
parent
c439747e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
11 deletions
+12
-11
request.go
request.go
+12
-11
No files found.
request.go
View file @
6f79696e
...
...
@@ -129,10 +129,18 @@ var converters = map[reflect.Kind]converter{
return
strconv
.
ParseBool
(
v
)
},
Int
:
func
(
v
string
)
(
interface
{},
error
)
{
return
strconv
.
ParseInt
(
v
,
0
,
32
)
val
,
err
:=
strconv
.
ParseInt
(
v
,
0
,
32
)
if
err
!=
nil
{
return
nil
,
err
}
return
int
(
val
),
err
},
Uint
:
func
(
v
string
)
(
interface
{},
error
)
{
return
strconv
.
ParseInt
(
v
,
0
,
32
)
val
,
err
:=
strconv
.
ParseUint
(
v
,
0
,
32
)
if
err
!=
nil
{
return
nil
,
err
}
return
int
(
val
),
err
},
Float
:
func
(
v
string
)
(
interface
{},
error
)
{
return
strconv
.
ParseFloat
(
v
,
64
)
...
...
@@ -140,8 +148,6 @@ var converters = map[reflect.Kind]converter{
}
func
(
r
*
request
)
ConvertOptions
()
error
{
converted
:=
make
(
map
[
string
]
interface
{})
for
k
,
v
:=
range
r
.
options
{
opt
,
ok
:=
r
.
optionDefs
[
k
]
if
!
ok
{
...
...
@@ -149,8 +155,6 @@ func (r *request) ConvertOptions() error {
}
kind
:=
reflect
.
TypeOf
(
v
)
.
Kind
()
var
value
interface
{}
if
kind
!=
opt
.
Type
{
if
kind
==
String
{
convert
:=
converters
[
opt
.
Type
]
...
...
@@ -163,14 +167,14 @@ func (r *request) ConvertOptions() error {
return
fmt
.
Errorf
(
"Could not convert string value '%s' to type '%s'"
,
v
,
opt
.
Type
.
String
())
}
value
=
val
r
.
options
[
k
]
=
val
}
else
{
return
fmt
.
Errorf
(
"Option '%s' should be type '%s', but got type '%s'"
,
k
,
opt
.
Type
.
String
(),
kind
.
String
())
}
}
else
{
value
=
v
r
.
options
[
k
]
=
v
}
for
_
,
name
:=
range
opt
.
Names
{
...
...
@@ -178,12 +182,9 @@ func (r *request) ConvertOptions() error {
return
fmt
.
Errorf
(
"Duplicate command options were provided ('%s' and '%s')"
,
k
,
name
)
}
converted
[
name
]
=
value
}
}
r
.
options
=
converted
return
nil
}
...
...
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