From b0546f737639aa99c709b6726bad660b436a4ddf Mon Sep 17 00:00:00 2001 From: robinbraemer Date: Wed, 16 Jun 2021 16:07:11 +0200 Subject: [PATCH] fix Int nil-pointer --- types.go | 65 +++++++++++++++++++++++++------------------------------- 1 file changed, 29 insertions(+), 36 deletions(-) diff --git a/types.go b/types.go index 1496de4..6ad8d95 100644 --- a/types.go +++ b/types.go @@ -9,21 +9,38 @@ import ( // Builtin argument types. var ( - Bool ArgumentType // Bool argument type. - - Int32 ArgumentType // Int32 argument type. - Int64 ArgumentType // Int64 argument type. - Int = Int32 // Int is an alias of Int32. - - Float32 ArgumentType // Float32 argument type. - Float64 ArgumentType // Float64 argument type. - // String argument type is quoted or unquoted. - String ArgumentType + String ArgumentType = QuotablePhase // StringWord argument type is a single word. - StringWord ArgumentType + StringWord ArgumentType = SingleWord // StringPhrase argument type is phrase. - StringPhrase ArgumentType + StringPhrase ArgumentType = GreedyPhrase + // Bool argument type. + Bool ArgumentType = &BoolArgumentType{} + + // Int32 argument type. + Int32 ArgumentType = &Int32ArgumentType{ + Min: MinInt32, + Max: MaxInt32, + } + // Int64 argument type. + Int64 ArgumentType = &Int64ArgumentType{ + Min: MinInt64, + Max: MaxInt64, + } + // Int is an alias of Int32. + Int = Int32 + + // Float32 argument type. + Float32 ArgumentType = &Float32ArgumentType{ + Min: MinFloat32, + Max: MaxFloat32, + } + // Float64 argument type. + Float64 ArgumentType = &Float64ArgumentType{ + Min: MinFloat64, + Max: MaxFloat64, + } ) // Default minimums and maximums of builtin numeric ArgumentType values. @@ -56,30 +73,6 @@ type ArgumentTypeFuncs struct { func (t *ArgumentTypeFuncs) Parse(rd *StringReader) (interface{}, error) { return t.ParseFn(rd) } func (t *ArgumentTypeFuncs) String() string { return t.Name } -// Initialize builtin argument types. -func init() { - Bool = &BoolArgumentType{} - Int32 = &Int32ArgumentType{ - Min: MinInt32, - Max: MaxInt32, - } - Int64 = &Int64ArgumentType{ - Min: MinInt64, - Max: MaxInt64, - } - Float32 = &Float32ArgumentType{ - Min: MinFloat32, - Max: MaxFloat32, - } - Float64 = &Float64ArgumentType{ - Min: MinFloat64, - Max: MaxFloat64, - } - String = QuotablePhase - StringWord = SingleWord - StringPhrase = GreedyPhrase -} - // Int returns the parsed int argument from the command context. // It returns the zero-value if not found. func (c *CommandContext) Int(argumentName string) int {