mirror of
https://github.com/EQEmu/eqemu-docs-v2.git
synced 2026-08-08 17:45:09 -04:00
[Generator] Add Server Rules Documentation Generator. (#43)
- Small cleanup in Command Generator to use fmt.Sprintf where useful.
This commit is contained in:
parent
4063a95908
commit
4366c94ffb
5 changed files with 955 additions and 565 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -13,6 +13,7 @@ func Run() error {
|
|||
NewQuestApiDocGeneratorCommand().Command(),
|
||||
NewDbGenerateDocsCommand().Command(),
|
||||
NewGMCommandsDocsGenerateCommand().Command(),
|
||||
NewServerRulesDocsGenerateCommand().Command(),
|
||||
}
|
||||
|
||||
cmd.AddCommand(commands...)
|
||||
|
|
|
|||
|
|
@ -59,39 +59,28 @@ func (c *GMCommandsDocsGenerateCommand) Handle(_ *cobra.Command, _ []string) {
|
|||
generatedTime := currentTime.Format("2006.01.02")
|
||||
template = strings.ReplaceAll(template, "{{generated_time}}", generatedTime)
|
||||
|
||||
commandData := template + "\n"
|
||||
commandData := fmt.Sprintf("%v\n", template)
|
||||
|
||||
commandData += "| Command | Description | Status Level |\n"
|
||||
|
||||
commandData = fmt.Sprintf("%v| :--- | :--- | :--- |\n", commandData)
|
||||
commandData += "| :--- | :--- | :--- |\n"
|
||||
|
||||
for _, line := range strings.Split(string(body), "\n") {
|
||||
if strings.Contains(line, "command_add(\"") {
|
||||
|
||||
//pp.Println(line)
|
||||
|
||||
line = strings.ReplaceAll(line, "command_add(", "")
|
||||
line = strings.ReplaceAll(line, "\t", "")
|
||||
|
||||
lineData := strings.Split(line, "\", ")
|
||||
|
||||
// command
|
||||
command := strings.TrimSpace(lineData[0])
|
||||
command = strings.ReplaceAll(command, "\"", "")
|
||||
|
||||
// help
|
||||
help := strings.TrimSpace(lineData[1])
|
||||
help = strings.ReplaceAll(help, "\"", "")
|
||||
help = strings.ReplaceAll(help, "|", "|")
|
||||
|
||||
// account status
|
||||
accountStatus := getStringInBetween(line, "AccountStatus::", ",")
|
||||
|
||||
//pp.Println(lineData)
|
||||
//pp.Println(command)
|
||||
//pp.Println(help)
|
||||
//pp.Println(accountStatus)
|
||||
|
||||
statusValue := GetStatusValue(accountStatus)
|
||||
|
||||
commandData += fmt.Sprintf(
|
||||
|
|
|
|||
115
internal/console/server_rules_doc_generator_cmd.go
Normal file
115
internal/console/server_rules_doc_generator_cmd.go
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
package console
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
type ServerRulesDocsGenerateCommand struct {
|
||||
command *cobra.Command
|
||||
}
|
||||
|
||||
func (c *ServerRulesDocsGenerateCommand) Command() *cobra.Command {
|
||||
return c.command
|
||||
}
|
||||
|
||||
func NewServerRulesDocsGenerateCommand() *ServerRulesDocsGenerateCommand {
|
||||
i := &ServerRulesDocsGenerateCommand{
|
||||
command: &cobra.Command{
|
||||
Use: "doc:server-rules",
|
||||
Short: "Command used for generated Server Rules Documentation",
|
||||
},
|
||||
}
|
||||
|
||||
i.command.Args = i.Validate
|
||||
i.command.Run = i.Handle
|
||||
|
||||
return i
|
||||
}
|
||||
|
||||
func (c *ServerRulesDocsGenerateCommand) Validate(_ *cobra.Command, _ []string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *ServerRulesDocsGenerateCommand) Handle(_ *cobra.Command, _ []string) {
|
||||
resp, err := http.Get("https://raw.githubusercontent.com/EQEmu/Server/master/common/ruletypes.h")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
b, err := ioutil.ReadFile("./templates/server-rules-page.template")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
template := string(b)
|
||||
|
||||
currentTime := time.Now()
|
||||
generatedTime := currentTime.Format("2006.01.02")
|
||||
template = strings.ReplaceAll(template, "{{generated_time}}", generatedTime)
|
||||
|
||||
serverRulesCategoryData := make(map[string]string)
|
||||
|
||||
serverRulesData := fmt.Sprintf("%v\n", template)
|
||||
|
||||
for _, line := range strings.Split(string(body), "\n") {
|
||||
if strings.HasPrefix(line, "RULE_BOOL(") || strings.HasPrefix(line, "RULE_INT(") || strings.HasPrefix(line, "RULE_REAL(") {
|
||||
currentLine := strings.ReplaceAll(line, "RULE_BOOL", "")
|
||||
currentLine = strings.ReplaceAll(currentLine, "RULE_INT", "")
|
||||
currentLine = strings.ReplaceAll(currentLine, "RULE_REAL", "")
|
||||
|
||||
lineData := strings.Split(currentLine, ", \"")
|
||||
|
||||
currentServerRuleData := strings.Split(lineData[0], ",")
|
||||
ruleType := strings.ReplaceAll(currentServerRuleData[0], "(", "")
|
||||
ruleName := strings.ReplaceAll(currentServerRuleData[1], " ", "")
|
||||
ruleName = fmt.Sprintf("%v:%v", ruleType, ruleName)
|
||||
ruleDefaultValue := currentServerRuleData[2]
|
||||
ruleDesc := strings.ReplaceAll(lineData[1], "\")", "")
|
||||
ruleDesc = strings.ReplaceAll(ruleDesc, "|", "|")
|
||||
|
||||
serverRulesCategoryData[ruleType] += fmt.Sprintf("| %v | %v | %v |\n", ruleName, ruleDefaultValue, ruleDesc)
|
||||
}
|
||||
}
|
||||
|
||||
keys := make([]string, 0)
|
||||
|
||||
for k, _ := range serverRulesCategoryData {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
|
||||
sort.Strings(keys)
|
||||
|
||||
for _, serverRuleType := range keys {
|
||||
serverRulesData += fmt.Sprintf("## %v Rules\n", serverRuleType)
|
||||
|
||||
serverRulesData += "| Rule Name | Default Value | Description |\n"
|
||||
|
||||
serverRulesData += "| :--- | :--- | :--- |\n"
|
||||
|
||||
lineEnding := "\n"
|
||||
|
||||
if serverRuleType == keys[len(keys)-1] {
|
||||
lineEnding = ""
|
||||
}
|
||||
|
||||
serverRulesData += fmt.Sprintf("%v%v", serverRulesCategoryData[serverRuleType], lineEnding)
|
||||
}
|
||||
|
||||
err = os.WriteFile("./docs/server/operation/server-rules.md", []byte(serverRulesData), os.ModePerm)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
}
|
||||
21
templates/server-rules-page.template
Normal file
21
templates/server-rules-page.template
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
---
|
||||
description: >-
|
||||
This page describes the Rules and Rule Values for your EQEmu Server. These
|
||||
rules are found in the rule_values table.
|
||||
---
|
||||
|
||||
# Server Rules
|
||||
|
||||
### Editing rules
|
||||
|
||||
To edit rules, you can use the [`#rules set [Name] [Value]`](https://docs.eqemu.io/server/operation/in-game-command-reference) command to set a rule.
|
||||
|
||||
You can then use [`#reload rules`](https://docs.eqemu.io/server/operation/loading-server-data/) to force all zones to reload the new rules.
|
||||
|
||||
!!! warning
|
||||
The `notes` field in the database is set by the server software. If you adjust the values in the field, they will be overwritten and restored to default values when you update your server binaries.
|
||||
|
||||
|
||||
!!! info
|
||||
If you would like to improve upon the descriptions or notes in the Server Rules table, please submit a pull request on the [ruletypes](https://github.com/EQEmu/Server/blob/master/common/ruletypes.h) header file.
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue