-
Notifications
You must be signed in to change notification settings - Fork 218
/
stats.go
112 lines (91 loc) · 1.88 KB
/
stats.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package main
import (
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/superfly/flyctl/internal/command"
"github.com/superfly/flyctl/internal/command/root"
)
func newStatsCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "stats",
Short: "Stats. Everybody loves stats.",
Run: func(cmd *cobra.Command, args []string) {
root := root.New()
stats := stats{}
walk(root, func(cmd *cobra.Command, depth int) {
stats.Commands.Total++
if cmd.Hidden {
stats.Commands.Hidden++
}
if cmd.Deprecated != "" {
stats.Commands.Deprecated++
}
if cmd.Runnable() {
stats.Commands.Runnable++
}
if cmd.HasExample() {
stats.Commands.WithExamples++
}
if command.IsAppsV1Command(cmd) {
stats.Commands.AppsV1++
}
stats.Commands.Aliases += len(cmd.Aliases)
cmd.Flags().VisitAll(func(f *pflag.Flag) {
stats.Flags.Total++
if f.Hidden {
stats.Flags.Hidden++
}
if f.Deprecated != "" {
stats.Flags.Deprecated++
}
if f.Shorthand != "" {
stats.Flags.WithShorthand++
}
})
})
stats.Root.Groups = len(root.Groups())
for _, cmd := range root.Commands() {
stats.Root.Commands++
if cmd.Hidden {
stats.Root.Hidden++
} else {
stats.Root.Visible++
}
if cmd.Deprecated != "" {
stats.Root.Deprecated++
}
if cmd.Runnable() {
stats.Root.Runnable++
}
}
prettyPrintJSON(stats)
},
}
return cmd
}
type stats struct {
Root struct {
Commands int
Hidden int
Visible int
Deprecated int
Runnable int
Groups int
}
Commands struct {
Total int
Runnable int
Hidden int
Deprecated int
WithExamples int
Aliases int
AppsV1 int
}
Flags struct {
Total int
Hidden int
Deprecated int
WithShorthand int
AppsV1 int
}
}