1package pflag
2
3import (
4	"fmt"
5	"strconv"
6)
7
8// -- int8 Value
9type int8Value int8
10
11func newInt8Value(val int8, p *int8) *int8Value {
12	*p = val
13	return (*int8Value)(p)
14}
15
16func (i *int8Value) Set(s string) error {
17	v, err := strconv.ParseInt(s, 0, 8)
18	*i = int8Value(v)
19	return err
20}
21
22func (i *int8Value) Type() string {
23	return "int8"
24}
25
26func (i *int8Value) String() string { return fmt.Sprintf("%v", *i) }
27
28func int8Conv(sval string) (interface{}, error) {
29	v, err := strconv.ParseInt(sval, 0, 8)
30	if err != nil {
31		return 0, err
32	}
33	return int8(v), nil
34}
35
36// GetInt8 return the int8 value of a flag with the given name
37func (f *FlagSet) GetInt8(name string) (int8, error) {
38	val, err := f.getFlagType(name, "int8", int8Conv)
39	if err != nil {
40		return 0, err
41	}
42	return val.(int8), nil
43}
44
45// Int8Var defines an int8 flag with specified name, default value, and usage string.
46// The argument p points to an int8 variable in which to store the value of the flag.
47func (f *FlagSet) Int8Var(p *int8, name string, value int8, usage string) {
48	f.VarP(newInt8Value(value, p), name, "", usage)
49}
50
51// Int8VarP is like Int8Var, but accepts a shorthand letter that can be used after a single dash.
52func (f *FlagSet) Int8VarP(p *int8, name, shorthand string, value int8, usage string) {
53	f.VarP(newInt8Value(value, p), name, shorthand, usage)
54}
55
56// Int8Var defines an int8 flag with specified name, default value, and usage string.
57// The argument p points to an int8 variable in which to store the value of the flag.
58func Int8Var(p *int8, name string, value int8, usage string) {
59	CommandLine.VarP(newInt8Value(value, p), name, "", usage)
60}
61
62// Int8VarP is like Int8Var, but accepts a shorthand letter that can be used after a single dash.
63func Int8VarP(p *int8, name, shorthand string, value int8, usage string) {
64	CommandLine.VarP(newInt8Value(value, p), name, shorthand, usage)
65}
66
67// Int8 defines an int8 flag with specified name, default value, and usage string.
68// The return value is the address of an int8 variable that stores the value of the flag.
69func (f *FlagSet) Int8(name string, value int8, usage string) *int8 {
70	p := new(int8)
71	f.Int8VarP(p, name, "", value, usage)
72	return p
73}
74
75// Int8P is like Int8, but accepts a shorthand letter that can be used after a single dash.
76func (f *FlagSet) Int8P(name, shorthand string, value int8, usage string) *int8 {
77	p := new(int8)
78	f.Int8VarP(p, name, shorthand, value, usage)
79	return p
80}
81
82// Int8 defines an int8 flag with specified name, default value, and usage string.
83// The return value is the address of an int8 variable that stores the value of the flag.
84func Int8(name string, value int8, usage string) *int8 {
85	return CommandLine.Int8P(name, "", value, usage)
86}
87
88// Int8P is like Int8, but accepts a shorthand letter that can be used after a single dash.
89func Int8P(name, shorthand string, value int8, usage string) *int8 {
90	return CommandLine.Int8P(name, shorthand, value, usage)
91}
92