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.

70 lines
1.2 KiB

package main
import (
"errors"
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
)
func install() error {
if isInstalled() {
return errors.New("gogo is already installed as go")
}
original, err := exec.LookPath("go")
if err != nil {
return err
}
this, err := os.Executable()
if err != nil {
return err
}
if err := os.Rename(original, filepath.Join(filepath.Dir(original), "_" + filepath.Base(original))); err != nil {
return err
}
if err := os.Rename(this, original); err != nil {
return err
}
fmt.Println("gogo installed as go")
return nil
}
func uninstall() error {
if !isInstalled() {
return errors.New("gogo is not installed as go")
}
this, err := os.Executable()
if err != nil {
return err
}
original := filepath.Join(filepath.Dir(this), "_" + filepath.Base(this))
if err := os.Remove(this); err != nil {
return err
}
if err := os.Rename(original, filepath.Join(filepath.Dir(original), filepath.Base(original)[1:])); err != nil {
return err
}
fmt.Println("gogo uninstalled as go")
return nil
}
func isInstalled() bool {
cmd := exec.Command("go", "--gadget")
out, err := cmd.Output()
if err != nil {
return false
}
return strings.EqualFold(string(out), goGoGadget)
}