-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1773 from urfave/rename-float64
Rename `float64` types from `Float64` to `Float`
- Loading branch information
Showing
11 changed files
with
151 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package cli | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
) | ||
|
||
type FloatFlag = FlagBase[float64, NoConfig, floatValue] | ||
|
||
// -- float64 Value | ||
type floatValue float64 | ||
|
||
// Below functions are to satisfy the ValueCreator interface | ||
|
||
func (f floatValue) Create(val float64, p *float64, c NoConfig) Value { | ||
*p = val | ||
return (*floatValue)(p) | ||
} | ||
|
||
func (f floatValue) ToString(b float64) string { | ||
return fmt.Sprintf("%v", b) | ||
} | ||
|
||
// Below functions are to satisfy the flag.Value interface | ||
|
||
func (f *floatValue) Set(s string) error { | ||
v, err := strconv.ParseFloat(s, 64) | ||
if err != nil { | ||
return err | ||
} | ||
*f = floatValue(v) | ||
return err | ||
} | ||
|
||
func (f *floatValue) Get() any { return float64(*f) } | ||
|
||
func (f *floatValue) String() string { return strconv.FormatFloat(float64(*f), 'g', -1, 64) } | ||
|
||
// Int looks up the value of a local IntFlag, returns | ||
// 0 if not found | ||
func (cCtx *Context) Float(name string) float64 { | ||
if v, ok := cCtx.Value(name).(float64); ok { | ||
return v | ||
} | ||
return 0 | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package cli | ||
|
||
import ( | ||
"flag" | ||
) | ||
|
||
type FloatSlice = SliceBase[float64, NoConfig, floatValue] | ||
type FloatSliceFlag = FlagBase[[]float64, NoConfig, FloatSlice] | ||
|
||
var NewFloatSlice = NewSliceBase[float64, NoConfig, floatValue] | ||
|
||
// FloatSlice looks up the value of a local FloatSliceFlag, returns | ||
// nil if not found | ||
func (cCtx *Context) FloatSlice(name string) []float64 { | ||
if fs := cCtx.lookupFlagSet(name); fs != nil { | ||
return lookupFloatSlice(name, fs) | ||
} | ||
return nil | ||
} | ||
|
||
func lookupFloatSlice(name string, set *flag.FlagSet) []float64 { | ||
f := set.Lookup(name) | ||
if f != nil { | ||
if slice, ok := f.Value.(flag.Getter).Get().([]float64); ok { | ||
return slice | ||
} | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.