forked from cornfeedhobo/pflag
-
Notifications
You must be signed in to change notification settings - Fork 1
/
complex128.go
82 lines (67 loc) · 2.67 KB
/
complex128.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package zflag
import (
"strconv"
"strings"
)
// -- complex128 Value
type complex128Value complex128
var _ Value = (*complex128Value)(nil)
var _ Getter = (*complex128Value)(nil)
var _ Typed = (*complex128Value)(nil)
func newComplex128Value(val complex128, p *complex128) *complex128Value {
*p = val
return (*complex128Value)(p)
}
func (f *complex128Value) Get() interface{} {
return complex128(*f)
}
func (f *complex128Value) Set(val string) error {
val = strings.TrimSpace(val)
v, err := strconv.ParseComplex(val, 128)
*f = complex128Value(v)
return err
}
func (f *complex128Value) Type() string {
return "complex128"
}
func (f *complex128Value) String() string { return strconv.FormatComplex(complex128(*f), 'g', -1, 128) }
// GetComplex128 return the complex128 value of a flag with the given name
func (fs *FlagSet) GetComplex128(name string) (complex128, error) {
val, err := fs.getFlagValue(name, "complex128")
if err != nil {
return 0, err
}
return val.(complex128), nil
}
// MustGetComplex128 is like GetComplex128, but panics on error.
func (fs *FlagSet) MustGetComplex128(name string) complex128 {
val, err := fs.GetComplex128(name)
if err != nil {
panic(err)
}
return val
}
// Complex128Var defines a complex128 flag with specified name, default value, and usage string.
// The argument p points to a complex128 variable in which to store the value of the flag.
func (fs *FlagSet) Complex128Var(p *complex128, name string, value complex128, usage string, opts ...Opt) {
fs.Var(newComplex128Value(value, p), name, usage, opts...)
}
// Complex128Var defines a complex128 flag with specified name, default value, and usage string.
// The argument p points to a complex128 variable in which to store the value of the flag.
func Complex128Var(p *complex128, name string, value complex128, usage string, opts ...Opt) {
CommandLine.Complex128Var(p, name, value, usage, opts...)
}
// Complex128 defines a complex128 flag with specified name, default value, and usage string.
// The return value is the address of a complex128 variable that stores the value of the flag.
func (fs *FlagSet) Complex128(name string, value complex128, usage string, opts ...Opt) *complex128 {
var p complex128
fs.Complex128Var(&p, name, value, usage, opts...)
return &p
}
// Complex128 defines a complex128 flag with specified name, default value, and usage string.
// The return value is the address of a complex128 variable that stores the value of the flag.
func Complex128(name string, value complex128, usage string, opts ...Opt) *complex128 {
return CommandLine.Complex128(name, value, usage, opts...)
}