forked from spf13/pflag
-
Notifications
You must be signed in to change notification settings - Fork 2
/
complex128.go
118 lines (95 loc) · 4.62 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build go1.15
package pflag
import "strconv"
// -- complex128 Value
type complex128Value complex128
func newComplex128Value(val complex128, p *complex128) *complex128Value {
*p = val
return (*complex128Value)(p)
}
func (f *complex128Value) Set(s string) error {
v, err := strconv.ParseComplex(s, 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) }
func complex128Conv(sval string) (interface{}, error) {
return strconv.ParseComplex(sval, 128)
}
// GetComplex128 return the complex128 value of a flag with the given name
func (f *FlagSet) GetComplex128(name string) (complex128, error) {
val, err := f.getFlagType(name, "complex128", complex128Conv)
if err != nil {
return 0, err
}
return val.(complex128), nil
}
// MustGetComplex128 is like GetComplex128, but panics on error.
func (f *FlagSet) MustGetComplex128(name string) complex128 {
val, err := f.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 (f *FlagSet) Complex128Var(p *complex128, name string, value complex128, usage string) {
f.Complex128VarP(p, name, "", value, usage)
}
// Complex128VarP is like Complex128Var, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) Complex128VarP(p *complex128, name, shorthand string, value complex128, usage string) {
f.VarP(newComplex128Value(value, p), name, shorthand, usage)
}
// Complex128VarS is like Complex128Var, but accepts a shorthand letter that can be used after a single dash, alone.
func (f *FlagSet) Complex128VarS(p *complex128, name, shorthand string, value complex128, usage string) {
f.VarS(newComplex128Value(value, p), name, shorthand, usage)
}
// 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) {
CommandLine.Complex128Var(p, name, value, usage)
}
// Complex128VarP is like Complex128Var, but accepts a shorthand letter that can be used after a single dash.
func Complex128VarP(p *complex128, name, shorthand string, value complex128, usage string) {
CommandLine.Complex128VarP(p, name, shorthand, value, usage)
}
// Complex128VarS is like Complex128Var, but accepts a shorthand letter that can be used after a single dash, alone.
func Complex128VarS(p *complex128, name, shorthand string, value complex128, usage string) {
CommandLine.Complex128VarS(p, name, shorthand, value, usage)
}
// 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 (f *FlagSet) Complex128(name string, value complex128, usage string) *complex128 {
return f.Complex128P(name, "", value, usage)
}
// Complex128P is like Complex128, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) Complex128P(name, shorthand string, value complex128, usage string) *complex128 {
p := new(complex128)
f.Complex128VarP(p, name, shorthand, value, usage)
return p
}
// Complex128S is like Complex128, but accepts a shorthand letter that can be used after a single dash, alone.
func (f *FlagSet) Complex128S(name, shorthand string, value complex128, usage string) *complex128 {
p := new(complex128)
f.Complex128VarS(p, name, shorthand, value, usage)
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) *complex128 {
return CommandLine.Complex128(name, value, usage)
}
// Complex128P is like Complex128, but accepts a shorthand letter that can be used after a single dash.
func Complex128P(name, shorthand string, value complex128, usage string) *complex128 {
return CommandLine.Complex128P(name, shorthand, value, usage)
}
// Complex128S is like Complex128, but accepts a shorthand letter that can be used after a single dash, alone.
func Complex128S(name, shorthand string, value complex128, usage string) *complex128 {
return CommandLine.Complex128S(name, shorthand, value, usage)
}