Skip to content

Commit

Permalink
fix Int nil-pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
robinbraemer committed Jun 16, 2021
1 parent 1f20951 commit b0546f7
Showing 1 changed file with 29 additions and 36 deletions.
65 changes: 29 additions & 36 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit b0546f7

Please sign in to comment.