fhelp/human.go

96 lines
2.0 KiB
Go

package fhelp
import (
"fmt"
"os"
"os/exec"
"runtime"
"go.wit.com/log"
)
func CheckProtoc() bool {
if !checkCmdSimple("protoc") {
userInstructions()
switch runtime.GOOS {
case "linux":
linuxInstall("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":
linuxInstall("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
}
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)
}