fhelp/human.go

96 lines
2.0 KiB
Go
Raw Normal View History

2025-01-13 08:12:06 -06:00
package fhelp
2025-01-13 02:50:01 -06:00
import (
"fmt"
"os"
"os/exec"
"runtime"
2025-01-13 02:50:01 -06:00
"go.wit.com/log"
)
func CheckProtoc() bool {
if !checkCmdSimple("protoc") {
2025-01-13 02:50:01 -06:00
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") {
2025-01-13 02:50:01 -06:00
return false
}
if !checkCmdSimple("protoc-gen-go") {
2025-01-13 02:50:01 -06:00
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") {
2025-01-13 02:50:01 -06:00
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
}
/*
2025-01-13 02:50:01 -06:00
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)
}
}
*/
2025-01-13 02:50:01 -06:00
// 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)
}