-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand.go
More file actions
59 lines (55 loc) · 1.16 KB
/
command.go
File metadata and controls
59 lines (55 loc) · 1.16 KB
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
package cli
import (
"reflect"
"strings"
)
type commandInfo struct {
name string
description string
longDescription string
aliases []string
hidden bool
examples []Example
}
func resolveInfo(cmd Commander) commandInfo {
info := commandInfo{
name: defaultName(cmd),
}
if n, ok := cmd.(Namer); ok {
if name := n.Name(); name != "" {
info.name = name
}
}
if d, ok := cmd.(Descriptor); ok {
if desc := d.Description(); desc != "" {
info.description = desc
}
}
if ld, ok := cmd.(LongDescriptor); ok {
if desc := ld.LongDescription(); desc != "" {
info.longDescription = desc
}
}
if a, ok := cmd.(Aliaser); ok {
if aliases := a.Aliases(); len(aliases) > 0 {
info.aliases = aliases
}
}
if h, ok := cmd.(Hider); ok {
// Note: Hidden() returning false is equivalent to not implementing Hider
info.hidden = h.Hidden()
}
if e, ok := cmd.(Exampler); ok {
if examples := e.Examples(); len(examples) > 0 {
info.examples = examples
}
}
return info
}
func defaultName(cmd Commander) string {
t := reflect.TypeOf(cmd)
if t.Kind() == reflect.Ptr {
t = t.Elem()
}
return strings.ToLower(t.Name())
}