summaryrefslogtreecommitdiff
path: root/buildPlugin.go
blob: 07500d987b829b0251e73d61dd7f804ee3c88857 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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/<pick one>/")
	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
}