func dir() (string, error) { str, err := exec.Command("brew", "--prefix").StringOutput(true) if err != nil { return "", err } return filepath.Join(str, "Library", "Formula"), nil }
func Env() (map[string]string, error) { b, err := exec.Command("brew", "--env").Output() if err != nil { return nil, err } return parseEnv(b), nil }
func Config() (map[string]string, error) { b, err := exec.Command("brew", "config").Output() if err != nil { return nil, err } return parseConfig(b), nil }
func Info(name string) (*Formula, error) { var ( f []Formula err = exec.Command("brew", "info", "--json=v1", name).RunJSON(&f) ) if err != nil { return nil, err } return &f[0], nil }
func ListInstalled() ([]*Formula, error) { var ( formulae = []*Formula{} err = exec.Command("brew", "info", "--installed", "--json=v1").RunJSON(&formulae) ) if err != nil { return nil, err } return formulae, nil }
func LocalVersion() (*Version, error) { var ( v Version fmt = "Homebrew %s (git revision %s last commit" ) err := exec.Command("brew", "--version").RunScanf(fmt, &v.Version, &v.Revision) if err != nil { return nil, err } // strip trailing ; v.Revision = v.Revision[:len(v.Revision)-1] return &v, nil }
func ListAll() ([]*Formula, error) { f, err := allFormulaNames() if err != nil { return nil, err } var ( formulae = []*Formula{} args = append([]string{"info", "--json=v1"}, f...) ) err = exec.Command("brew", args...).RunJSON(&formulae) if err != nil { return nil, err } return formulae, nil }
func Upgrade(name string) (string, error) { return exec.Command("brew", "upgrade", name).StringOutput(true) }
func Remove(name string) (string, error) { return exec.Command("brew", "remove", name).StringOutput(true) }
func Install(name string) (string, error) { return exec.Command("brew", "install", name).StringOutput(true) }