8 func newIntValue(val int, p *int) *intValue {
13 func (i *intValue) Set(s string) error {
14 v, err := strconv.ParseInt(s, 0, 64)
19 func (i *intValue) Type() string {
23 func (i *intValue) String() string { return strconv.Itoa(int(*i)) }
25 func intConv(sval string) (interface{}, error) {
26 return strconv.Atoi(sval)
29 // GetInt return the int value of a flag with the given name
30 func (f *FlagSet) GetInt(name string) (int, error) {
31 val, err := f.getFlagType(name, "int", intConv)
38 // IntVar defines an int flag with specified name, default value, and usage string.
39 // The argument p points to an int variable in which to store the value of the flag.
40 func (f *FlagSet) IntVar(p *int, name string, value int, usage string) {
41 f.VarP(newIntValue(value, p), name, "", usage)
44 // IntVarP is like IntVar, but accepts a shorthand letter that can be used after a single dash.
45 func (f *FlagSet) IntVarP(p *int, name, shorthand string, value int, usage string) {
46 f.VarP(newIntValue(value, p), name, shorthand, usage)
49 // IntVar defines an int flag with specified name, default value, and usage string.
50 // The argument p points to an int variable in which to store the value of the flag.
51 func IntVar(p *int, name string, value int, usage string) {
52 CommandLine.VarP(newIntValue(value, p), name, "", usage)
55 // IntVarP is like IntVar, but accepts a shorthand letter that can be used after a single dash.
56 func IntVarP(p *int, name, shorthand string, value int, usage string) {
57 CommandLine.VarP(newIntValue(value, p), name, shorthand, usage)
60 // Int defines an int flag with specified name, default value, and usage string.
61 // The return value is the address of an int variable that stores the value of the flag.
62 func (f *FlagSet) Int(name string, value int, usage string) *int {
64 f.IntVarP(p, name, "", value, usage)
68 // IntP is like Int, but accepts a shorthand letter that can be used after a single dash.
69 func (f *FlagSet) IntP(name, shorthand string, value int, usage string) *int {
71 f.IntVarP(p, name, shorthand, value, usage)
75 // Int defines an int flag with specified name, default value, and usage string.
76 // The return value is the address of an int variable that stores the value of the flag.
77 func Int(name string, value int, usage string) *int {
78 return CommandLine.IntP(name, "", value, usage)
81 // IntP is like Int, but accepts a shorthand letter that can be used after a single dash.
82 func IntP(name, shorthand string, value int, usage string) *int {
83 return CommandLine.IntP(name, shorthand, value, usage)