1
0
mirror of https://github.com/golang/go synced 2024-11-21 19:54:41 -07:00

flag: allow hexadecimal and octal input for integer flags.

R=r
CC=golang-dev
https://golang.org/cl/4182043
This commit is contained in:
Luuk van Dijk 2011-02-11 12:23:54 +01:00
parent 28a2369414
commit 37b1787392
2 changed files with 7 additions and 7 deletions

View File

@ -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 {
} }
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 {
} }
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 {
} }
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
} }

View File

@ -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) {
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)