From 2e70eb3f128f9161c04531b9451905ede74c16ce Mon Sep 17 00:00:00 2001 From: Charlie O'Keefe Date: Thu, 6 Jan 2022 21:57:46 -0700 Subject: [PATCH] Restore zcash.go --- script/zcash.go | 100 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 script/zcash.go diff --git a/script/zcash.go b/script/zcash.go new file mode 100644 index 0000000..e1414c9 --- /dev/null +++ b/script/zcash.go @@ -0,0 +1,100 @@ +package main + +import ( + "html/template" + "io" + "os" + "os/exec" + "strings" +) + +type Command struct { + Name string + Description string +} + +type Group struct { + Name string + Commands []Command +} + +type Document struct { + Command *Command + Groups []Group +} + +func main() { + first := run("help") + split := strings.Split(first, "\n") + + groups := make([]Group, 0) + commands := make([]Command, 0) + lastGroupName := "" + + for _, line := range split { + if len(line) > 0 { + if strings.HasPrefix(line, "== ") { + if len(commands) != 0 { + g := Group{ + Name: lastGroupName, + Commands: commands, + } + groups = append(groups, g) + commands = make([]Command, 0) + } + lastGroupName = line[3 : len(line)-3] + } else { + name := strings.Split(line, " ")[0] + desc := run("help", name) + comm := Command{ + Name: name, + Description: desc, + } + commands = append(commands, comm) + } + } + } + + g := Group{ + Name: lastGroupName, + Commands: commands, + } + groups = append(groups, g) + + tmpl := template.Must(template.ParseFiles("template.html")) + tmpl.Execute(open("../index.html"), Document{ + Command: nil, + Groups: groups, + }) + + for _, group := range groups { + for _, command := range group.Commands { + tmpl.Execute(open("../"+command.Name+".html"), Document{ + Command: &command, + Groups: groups, + }) + } + } +} + +func check(e error) { + if e != nil { + panic(e) + } +} + +func open(path string) io.Writer { + f, err := os.Create(path) + // not closing, program will close sooner + check(err) + return f +} + +func run(args ...string) string { + out, err := exec.Command("/home/marsh/v4.5.1-1_github_docs/zcash/src/zcash-cli", args...).CombinedOutput() + if err != nil { + panic(err) + } + + return string(out) +}