67 lines
1.3 KiB
Go
67 lines
1.3 KiB
Go
//go:build runbooktest
|
|
// +build runbooktest
|
|
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"ops-assistant/internal/core/ops"
|
|
)
|
|
|
|
func main() {
|
|
if len(os.Args) < 4 {
|
|
fmt.Println("usage: runbook_test <db_path> <base_dir> <command_text>")
|
|
os.Exit(2)
|
|
}
|
|
dbPath := os.Args[1]
|
|
baseDir := os.Args[2]
|
|
cmd := os.Args[3]
|
|
inputs := map[string]string{}
|
|
// minimal parse for /cf dnsadd <name> <content> [true] [type]
|
|
parts := split(cmd)
|
|
if len(parts) >= 4 && parts[0] == "/cf" && parts[1] == "dnsadd" {
|
|
inputs["name"] = parts[2]
|
|
inputs["content"] = parts[3]
|
|
inputs["type"] = "A"
|
|
inputs["proxied"] = "false"
|
|
if len(parts) >= 5 {
|
|
if parts[4] == "true" {
|
|
inputs["proxied"] = "true"
|
|
if len(parts) >= 6 {
|
|
inputs["type"] = parts[5]
|
|
}
|
|
} else {
|
|
inputs["type"] = parts[4]
|
|
}
|
|
}
|
|
}
|
|
jobID, _, err := ops.RunOnce(dbPath, filepath.Clean(baseDir), cmd, "cf_dns_add", 1, inputs)
|
|
if err != nil {
|
|
fmt.Printf("ERR: %v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
fmt.Printf("OK job=%d\n", jobID)
|
|
}
|
|
|
|
func split(s string) []string {
|
|
out := []string{}
|
|
cur := ""
|
|
for _, r := range s {
|
|
if r == ' ' || r == '\t' || r == '\n' {
|
|
if cur != "" {
|
|
out = append(out, cur)
|
|
cur = ""
|
|
}
|
|
continue
|
|
}
|
|
cur += string(r)
|
|
}
|
|
if cur != "" {
|
|
out = append(out, cur)
|
|
}
|
|
return out
|
|
}
|