summaryrefslogtreecommitdiff
path: root/human.go
blob: 5a459b43d9108beea373feff29c38e39503d9407 (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package fhelp

import (
	"fmt"
	"os"
	"os/exec"
	"runtime"

	"go.wit.com/log"
)

func CheckProtoc() bool {
	if !checkCmdSimple("protoc") {
		userInstructions()
		switch runtime.GOOS {
		case "linux":
			Install("protoc")
		case "macos":
			log.Info("todo: print instructions here for installing protoc on macos. brew install?")
		case "windows":
			log.Info("todo: print instructions here for installing protoc on windows")
		default:
			log.Info("todo: print instructions here for installing protoc on", runtime.GOOS)
		}
		return false
	}
	if !checkCmdSimple("protoc") {
		return false
	}

	if !checkCmdSimple("protoc-gen-go") {
		userInstructions()
		switch runtime.GOOS {
		case "linux":
			Install("protoc-gen-go")
		case "macos":
			log.Info("todo: print instructions here for installing protoc on macos. brew install?")
		case "windows":
			log.Info("todo: print instructions here for installing protoc on windows")
		default:
			log.Info("todo: print instructions here for installing protoc on", runtime.GOOS)
		}
	}
	if !checkCmdSimple("protoc-gen-go") {
		return false
	}
	return true
}

func checkCmdSimple(cmd string) bool {
	path, err := exec.LookPath(cmd)
	if err != nil {
		fmt.Printf("\n%s is not in the PATH\n", cmd)
		return false
	} else {
		fmt.Printf("%s is available at %s\n", cmd, path)
	}
	return true
}

// never output anythhing to stdout or stderr here
func CheckCmd(cmd string) (string, error) {
	path, err := exec.LookPath(cmd)
	if err != nil {
		// fmt.Printf("\n%s is not in the PATH\n", cmd)
	} else {
		// fmt.Printf("%s is available at %s\n", cmd, path)
	}
	return path, err
}

/*

func oldcheckCmd(cmd string) {
	// path, err := exec.LookPath(cmd)
	_, err := exec.LookPath(cmd)
	if err != nil {
		// fmt.Printf("\n%s is not in the PATH\n", cmd)
		userInstructions()
		log.Sleep(2)
	} else {
		// fmt.Printf("%s is available at %s\n", cmd, path)
	}
}
*/

// todo: figure out how to determine, in a package, what the program name is
func okExit(s string) {
	log.Info("<program> ok", s)
	os.Exit(0)
}

func badExit(err error) {
	log.Info("<program> error:", err)
	os.Exit(-1)
}