Compare commits

...

3 Commits

Author SHA1 Message Date
Jeff Carr ef24c64f5b expose func 2025-02-22 06:53:10 -06:00
Jeff Carr 06564368bc first attempt to install protoc on linux 2025-02-12 15:10:50 -06:00
Jeff Carr 815d061d5d add help for 'go-mod-clean' 2025-01-17 05:13:25 -06:00
3 changed files with 97 additions and 5 deletions

30
goModClean.go Normal file
View File

@ -0,0 +1,30 @@
package fhelp
import (
"fmt"
"go.wit.com/log"
)
func CheckGoModClean() bool {
if checkCmdSimple("go-mod-clean") {
return true
}
goModCleanInstructions()
return false
}
func CheckGoModCleanExit() {
if CheckGoModClean() {
return
}
badExit(fmt.Errorf("missing go-mod-clean"))
}
func goModCleanInstructions() {
log.Info("you are missing 'go-mod-clean' which is required")
log.Info("")
log.Info("you can:")
log.Info(" go install go.wit.com/apps/utils/go-mod-clean # if you have go")
log.Info("")
}

View File

@ -4,19 +4,44 @@ import (
"fmt" "fmt"
"os" "os"
"os/exec" "os/exec"
"runtime"
"go.wit.com/log" "go.wit.com/log"
) )
func CheckProtoc() bool { func CheckProtoc() bool {
if checkCmdSimple("protoc") { if !checkCmdSimple("protoc") {
userInstructions() userInstructions()
log.Sleep(2) 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 return false
} }
if checkCmdSimple("protoc-gen-go") { if !checkCmdSimple("protoc") {
return false
}
if !checkCmdSimple("protoc-gen-go") {
userInstructions() userInstructions()
log.Sleep(2) 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 false
} }
return true return true
@ -33,7 +58,7 @@ func checkCmdSimple(cmd string) bool {
return true return true
} }
func checkCmd(cmd string) (string, error) { func CheckCmd(cmd string) (string, error) {
path, err := exec.LookPath(cmd) path, err := exec.LookPath(cmd)
if err != nil { if err != nil {
fmt.Printf("\n%s is not in the PATH\n", cmd) fmt.Printf("\n%s is not in the PATH\n", cmd)
@ -43,6 +68,8 @@ func checkCmd(cmd string) (string, error) {
return path, err return path, err
} }
/*
func oldcheckCmd(cmd string) { func oldcheckCmd(cmd string) {
// path, err := exec.LookPath(cmd) // path, err := exec.LookPath(cmd)
_, err := exec.LookPath(cmd) _, err := exec.LookPath(cmd)
@ -54,6 +81,7 @@ func oldcheckCmd(cmd string) {
// fmt.Printf("%s is available at %s\n", cmd, path) // fmt.Printf("%s is available at %s\n", cmd, path)
} }
} }
*/
// todo: figure out how to determine, in a package, what the program name is // todo: figure out how to determine, in a package, what the program name is
func okExit(s string) { func okExit(s string) {

34
linux.go Normal file
View File

@ -0,0 +1,34 @@
package fhelp
// auto run protoc with the correct args
import (
"bufio"
"fmt"
"os"
"strings"
"go.wit.com/lib/gui/shell"
"go.wit.com/log"
)
func linuxInstall(pkg string) {
cmd := []string{"apt", "install", "-y", pkg}
if pkg == "protoc" {
cmd = []string{"apt", "install", "-y", "protobuf-compiler"}
}
log.Info("Would you like to run", "sudo", cmd, "now?")
fmt.Fprintf(os.Stdout, "(y)es or (n)o ? ")
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
line := scanner.Text()
line = strings.TrimSpace(line)
line = strings.ToLower(line)
switch line {
case "y":
shell.Sudo(cmd)
default:
}
}
}