diff --git a/buildPlugin.go b/buildPlugin.go new file mode 100644 index 0000000..07500d9 --- /dev/null +++ b/buildPlugin.go @@ -0,0 +1,64 @@ +package fhelp + +import ( + "bufio" + "fmt" + "os" + "strings" + + "go.wit.com/lib/gui/shell" + "go.wit.com/log" +) + +func BuildPlugin(pname string) bool { + if CheckProtoc() { + log.Info("You have the right tools for protobufs") + } else { + log.Info("You do not have the right tools for protobufs") + } + + log.Info("") + log.Info("### Error ####") + log.Info("The GUI golang plugins did not load for the", pname) + log.Info("You will have to rebuild them") + log.Info("go-clone go.wit.com/toolkits//") + log.Info("TODO: try to rebuild them here") + log.Info("TODO: falling back to STDIN interface") + log.Info("### Error ####") + log.Info("") + log.Infof("To attempt to build the %s plugin, run:\n", pname) + log.Info("forge --build go.wit.com/toolkits/gocui") + log.Info("") + if !questionUser() { + return false + } + r := shell.RunRealtime([]string{"forge", "--build", "go.wit.com/toolkits/" + pname}) + if r.Error == nil { + log.Info("build worked") + log.Info("You must copy that file to ~/go/lib/go-gui/") + return true + } else { + log.Info("build failed") + } + return false +} + +func questionUser() bool { + log.Info("Would you like to run that now?") + fmt.Fprintf(os.Stdout, "(y)es or (n)o ? ") + + scanner := bufio.NewScanner(os.Stdin) + for scanner.Scan() { + line := scanner.Text() + line = strings.TrimSpace(line) + line = strings.ToLower(line) + switch line { + case "y": + return true + case "n": + return false + default: + } + } + return false +}