getopt: init module
This commit is contained in:
parent
8290a04536
commit
2729e58eab
17 changed files with 1076 additions and 3 deletions
33
getopt/float.go
Normal file
33
getopt/float.go
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
package getopt
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type floatVal float64
|
||||
|
||||
func (f *floatVal) String() string {
|
||||
return fmt.Sprint(float64(*f))
|
||||
}
|
||||
|
||||
func (f *floatVal) Set(val string) error {
|
||||
_, err := fmt.Sscanf(val, "%g", f)
|
||||
return err
|
||||
}
|
||||
|
||||
// Float64Var defines a float64 flag with specified name, default value,
|
||||
// and usage string. The argument p points to a float64 variable in
|
||||
// which to store the value of the flag.
|
||||
func (set *FlagSet) Float64Var(p *float64, name string, value float64, usage string) {
|
||||
*p = value
|
||||
set.Var((*floatVal)(p), name, usage)
|
||||
}
|
||||
|
||||
// Float64 defines a float64 flag with specified name, default value,
|
||||
// and usage string. The return value is the address of a float64
|
||||
// variable that stores the value of the flag.
|
||||
func (set *FlagSet) Float64(name string, value float64, usage string) *float64 {
|
||||
var f float64
|
||||
set.Float64Var(&f, name, value, usage)
|
||||
return &f
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue