diff options
Diffstat (limited to 'human.go')
| -rw-r--r-- | human.go | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/human.go b/human.go new file mode 100644 index 0000000..79780ee --- /dev/null +++ b/human.go @@ -0,0 +1,67 @@ +package main + +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) +} |
