-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflag.go
60 lines (52 loc) · 929 Bytes
/
flag.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
package spec
import (
"strings"
"github.com/urfave/cli/v2"
)
type flag struct {
cli.Flag
}
func (f flag) Name() string {
return f.Names()[0]
}
func (f flag) Shorthand() string {
for _, name := range f.Names() {
if len(name) == 1 {
return "-" + name
}
}
return ""
}
func (f flag) TakesValue() bool {
if docFlag, ok := f.Flag.(cli.DocGenerationFlag); ok {
return docFlag.TakesValue()
}
return false
}
func (f flag) TakesFile() bool {
switch flag := f.Flag.(type) {
case *cli.GenericFlag:
if flag.TakesFile {
return true
}
case *cli.StringFlag:
if flag.TakesFile {
return true
}
case *cli.StringSliceFlag:
if flag.TakesFile {
return true
}
case *cli.PathFlag:
if flag.TakesFile {
return true
}
}
return false
}
func (f flag) Usage() string {
if docFlag, ok := f.Flag.(cli.DocGenerationFlag); ok {
return strings.SplitN(docFlag.GetUsage(), "\n", 2)[0]
}
return ""
}