fhelp/human.go

68 lines
1.2 KiB
Go

package fhelp
import (
"fmt"
"os"
"os/exec"
"go.wit.com/log"
)
func CheckProtoc() bool {
if checkCmdSimple("protoc") {
userInstructions()
log.Sleep(2)
return false
}
if checkCmdSimple("protoc-gen-go") {
userInstructions()
log.Sleep(2)
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)
}