Go, but with gadgets!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
1.4 KiB

package main
import (
"flag"
"fmt"
"os"
"os/exec"
"path/filepath"
)
const goGoGadget = "https://en.wikipedia.org/wiki/Inspector_Gadget"
func main() {
fs := flag.NewFlagSet("gogo", flag.ContinueOnError)
listFlag := fs.Bool("list", false, "list gadgets")
installFlag := fs.Bool("install", false, "install gogo as go")
uninstallFlag := fs.Bool("uninstall", false, "uninstall gogo as go")
gadgetFlag := fs.Bool("gadget", false, "go go gadget!")
fs.Usage = func() {}
fs.Parse(os.Args[1:])
if *gadgetFlag {
fmt.Print(goGoGadget)
return
}
if *listFlag {
fmt.Println("Available Gadgets:")
for _, gadget := range listGadgets() {
fmt.Println("\t", gadget)
}
return
}
if *installFlag {
if err := install(); err != nil {
fmt.Println(err)
}
return
}
if *uninstallFlag {
if err := uninstall(); err != nil {
fmt.Println(err)
}
return
}
// Run Go
binPath, err := exec.LookPath("go")
if err != nil {
fmt.Println("go cannot be found in PATH")
return
}
if isInstalled() {
binPath = filepath.Join(filepath.Dir(binPath), "_"+filepath.Base(binPath))
}
args := os.Args[1:]
if len(args) > 0 {
if extPath, err := exec.LookPath("go-" + args[0]); err == nil {
args = args[1:]
binPath = extPath
}
}
bin := exec.Command(binPath, args...)
bin.Stdin = os.Stdin
bin.Stdout = os.Stdout
bin.Stderr = os.Stderr
_ = bin.Run()
}