Commit 37b17873 authored by Luuk van Dijk's avatar Luuk van Dijk

flag: allow hexadecimal and octal input for integer flags.

R=r
CC=golang-dev
https://golang.org/cl/4182043
parent 28a23694
...@@ -96,7 +96,7 @@ func newIntValue(val int, p *int) *intValue { ...@@ -96,7 +96,7 @@ func newIntValue(val int, p *int) *intValue {
} }
func (i *intValue) Set(s string) bool { func (i *intValue) Set(s string) bool {
v, err := strconv.Atoi(s) v, err := strconv.Btoi64(s, 0)
*i = intValue(v) *i = intValue(v)
return err == nil return err == nil
} }
...@@ -112,7 +112,7 @@ func newInt64Value(val int64, p *int64) *int64Value { ...@@ -112,7 +112,7 @@ func newInt64Value(val int64, p *int64) *int64Value {
} }
func (i *int64Value) Set(s string) bool { func (i *int64Value) Set(s string) bool {
v, err := strconv.Atoi64(s) v, err := strconv.Btoi64(s, 0)
*i = int64Value(v) *i = int64Value(v)
return err == nil return err == nil
} }
...@@ -128,7 +128,7 @@ func newUintValue(val uint, p *uint) *uintValue { ...@@ -128,7 +128,7 @@ func newUintValue(val uint, p *uint) *uintValue {
} }
func (i *uintValue) Set(s string) bool { func (i *uintValue) Set(s string) bool {
v, err := strconv.Atoui(s) v, err := strconv.Btoui64(s, 0)
*i = uintValue(v) *i = uintValue(v)
return err == nil return err == nil
} }
...@@ -144,7 +144,7 @@ func newUint64Value(val uint64, p *uint64) *uint64Value { ...@@ -144,7 +144,7 @@ func newUint64Value(val uint64, p *uint64) *uint64Value {
} }
func (i *uint64Value) Set(s string) bool { func (i *uint64Value) Set(s string) bool {
v, err := strconv.Atoui64(s) v, err := strconv.Btoui64(s, 0)
*i = uint64Value(v) *i = uint64Value(v)
return err == nil return err == nil
} }
......
...@@ -106,7 +106,7 @@ func TestParse(t *testing.T) { ...@@ -106,7 +106,7 @@ func TestParse(t *testing.T) {
"-bool", "-bool",
"-bool2=true", "-bool2=true",
"--int", "22", "--int", "22",
"--int64", "23", "--int64", "0x23",
"-uint", "24", "-uint", "24",
"--uint64", "25", "--uint64", "25",
"-string", "hello", "-string", "hello",
...@@ -125,8 +125,8 @@ func TestParse(t *testing.T) { ...@@ -125,8 +125,8 @@ func TestParse(t *testing.T) {
if *intFlag != 22 { if *intFlag != 22 {
t.Error("int flag should be 22, is ", *intFlag) t.Error("int flag should be 22, is ", *intFlag)
} }
if *int64Flag != 23 { if *int64Flag != 0x23 {
t.Error("int64 flag should be 23, is ", *int64Flag) t.Error("int64 flag should be 0x23, is ", *int64Flag)
} }
if *uintFlag != 24 { if *uintFlag != 24 {
t.Error("uint flag should be 24, is ", *uintFlag) t.Error("uint flag should be 24, is ", *uintFlag)
......
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