-
Notifications
You must be signed in to change notification settings - Fork 0
/
boolflag.go
53 lines (47 loc) · 1.05 KB
/
boolflag.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
package argumentative
import (
"fmt"
)
// struct for a single configured flag
type BoolFlag struct {
Longflag string
Shortflag string
Description string
Required bool
Value *bool
}
// Factory to generate a new flag
func NewBoolFlag(longflag string, shortflag string, description string) BoolFlag {
flag := BoolFlag{
Longflag: longflag,
Shortflag: shortflag,
Description: description,
Value: new(bool),
}
*flag.Value = false
return flag
}
// Generate the string for the long description
func (f *BoolFlag) GetLongDescription() string {
flagnames := ""
if f.Shortflag != "" {
flagnames += "-" + f.Shortflag + ", "
}
flagnames += "--" + f.Longflag
output := fmt.Sprintf("%-25s", flagnames)
if f.Description != "" {
output += f.Description
}
return output
}
// Generate the string for a short description in the 'Usage:' line
func (f *BoolFlag) GetShortDescription() string {
output := " ["
if f.Shortflag != "" {
output += "-" + f.Shortflag
} else {
output += "--" + f.Longflag
}
output += "]"
return output
}