[docs] add docbuilder.go

This commit is contained in:
2023-10-30 22:56:21 +01:00
parent b08446bbff
commit 58946000e1
3 changed files with 4 additions and 91 deletions

View File

@@ -13,12 +13,11 @@ import (
func getMarkdown(documenter internal.Documenter) string { func getMarkdown(documenter internal.Documenter) string {
var result string var result string
result += fmt.Sprintf("# %v\n**%v**\n\nValues:\n", documenter.GetName(), documenter.GetDescription()) result += fmt.Sprintf("# %v\n%v\n## Options:\n", documenter.GetName(), documenter.GetDescription())
for _, opt := range documenter.GetOptions() { for _, opt := range documenter.GetOptions() {
result += fmt.Sprintf("- Name: **%v**\n\t- Type: %v\n\t- Descr: %v\n\t- Default: %v\n", result += fmt.Sprintf("### %v\n%v \n\n*Type:* %v \n\n*Default:* ```%v``` \n",
opt.Name, opt.Type, opt.Description, opt.Default) opt.Name, opt.Description, opt.Type, opt.Default)
result += "\n\n"
} }
return result return result

2
go.mod
View File

@@ -1,3 +1,3 @@
module unknown.com/gokill module unknown.com/gokill
go 1.20 go 1.21.3

View File

@@ -1,86 +0,0 @@
package main
import (
"encoding/json"
"flag"
"fmt"
"os"
"unknown.com/gokill/actions"
"unknown.com/gokill/internal"
"unknown.com/gokill/triggers"
)
func GetDocumentation() string {
actions := actions.GetDocumenters()
var result string
writeOptions := func(documenters []internal.Documenter) {
for _, act := range documenters {
result += fmt.Sprintf("\n### %v\nDescription: %v \nValues:\n", act.GetName(), act.GetDescription())
for _, opt := range act.GetOptions() {
result += fmt.Sprintf("- Name: **%v**\n\t- Type: %v\n\t- Descr: %v\n\t- Default: %v\n",
opt.Name, opt.Type, opt.Description, opt.Default)
result += "\n\n"
}
}
}
result = "# Available Triggers:\n\n"
writeOptions(triggers.GetDocumenters())
result += "\n\n# Available Actions:\n\n"
writeOptions(actions)
return result
}
func main() {
configFilePath := flag.String("c", "", "path to config file")
showDoc := flag.Bool("d", false, "show doc")
testRun := flag.Bool("t", false, "test run")
flag.Parse()
if *showDoc {
fmt.Print(GetDocumentation())
return
}
if *configFilePath == "" {
fmt.Println("No config file given. Use --help to show usage.")
return
}
actions.TestRun = *testRun
configFile, err := os.ReadFile(*configFilePath)
if err != nil {
fmt.Println("Error loading config file: ", err)
return
}
var f []internal.KillSwitchConfig
err = json.Unmarshal(configFile, &f)
if err != nil {
fmt.Println(err)
return
}
var triggerList []triggers.Trigger
for _, cfg := range f {
trigger, err := triggers.NewTrigger(cfg)
if err != nil {
fmt.Println(err)
return
}
trigger.Listen() //TODO: not block here
triggerList = append(triggerList, trigger)
}
}