-
Notifications
You must be signed in to change notification settings - Fork 938
/
gen-docs.go
134 lines (104 loc) · 3.26 KB
/
gen-docs.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package run
import (
"bytes"
"fmt"
"github.com/jonas747/yagpdb/common/config"
"os"
"sort"
"strings"
"github.com/jonas747/dcmd"
"github.com/jonas747/yagpdb/commands"
)
func GenCommandsDocs() {
// func GenerateHelp(d *Data, container *Container, formatter HelpFormatter) (embeds []*discordgo.MessageEmbed) {
sets := dcmd.SortCommands(commands.CommandSystem.Root, commands.CommandSystem.Root)
var out bytes.Buffer
out.WriteString("## Legend\n\n")
out.WriteString("`<required arg>` `[optional arg]`\n\n")
out.WriteString("Text arguments containing multiple words needs be to put in quotes (\"arg here\") or code ticks (`arg here`) if it's not the last argument and there's more than 1 text argument.\n\n")
out.WriteString("For example with the poll command if you want the question to have multiple words: `-poll \"whats your favorite color\" red blue green2`\n\n")
stdHelpFmt := &dcmd.StdHelpFormatter{}
mockCmdData := &dcmd.Data{}
for _, set := range sets {
out.WriteString("## " + set.Name() + " " + set.Emoji() + "\n\n")
for _, entry := range set.Commands {
// get the main name
nameStr := entry.Container.FullName(false)
if nameStr != "" {
nameStr += " "
}
nameStr += entry.Cmd.Trigger.Names[0]
// then aliases
aliases := strings.Join(entry.Cmd.Trigger.Names[1:], "/")
// arguments and switches
args := stdHelpFmt.ArgDefs(entry.Cmd, mockCmdData)
switches := stdHelpFmt.Switches(entry.Cmd.Command)
// grab the description
desc := ""
if cast, ok := entry.Cmd.Command.(dcmd.CmdWithDescriptions); ok {
short, long := cast.Descriptions(mockCmdData)
if long != "" {
desc = long
} else if short != "" {
desc = short
} else {
desc = "No description for this command"
}
}
out.WriteString("### " + nameStr + "\n\n")
if aliases != "" {
out.WriteString("**Aliases:** " + aliases + "\n\n")
}
out.WriteString(desc)
out.WriteString("\n\n")
out.WriteString("**Usage:**\n")
out.WriteString("```\n" + args + "\n```\n")
if switches != "" {
out.WriteString("```\n" + switches + "\n```\n")
}
out.WriteString("\n")
}
}
os.Stdout.Write(out.Bytes())
return
}
func GenConfigDocs() {
keys := make([]string, 0, len(config.Singleton.Options))
for k, _ := range config.Singleton.Options {
keys = append(keys, k)
}
sort.Strings(keys)
var out bytes.Buffer
for _, k := range keys {
v := config.Singleton.Options[k]
out.WriteString("**" + v.Description + "**")
typeStr := ""
def := ""
switch t := v.DefaultValue.(type) {
case string:
typeStr = "string"
def = t
case bool:
typeStr = "true/false"
def = "true"
if !t {
def = "false"
}
case int, uint, float32, float64, int8, int16, int32, int64, uint8, uint16, uint32, uint64:
typeStr = "number"
def = fmt.Sprint(t)
}
if typeStr != "" {
out.WriteString(" (" + typeStr)
if def != "" {
out.WriteString(", default: " + def)
}
out.WriteString(")")
}
out.WriteString("\n")
properKey := strings.ToUpper(v.Name)
properKey = strings.Replace(properKey, ".", "_", -1)
out.WriteString(properKey + "\n\n")
}
os.Stdout.Write(out.Bytes())
}