Пример #1
0
func dir() (string, error) {
	str, err := exec.Command("brew", "--prefix").StringOutput(true)

	if err != nil {
		return "", err
	}

	return filepath.Join(str, "Library", "Formula"), nil
}
Пример #2
0
func Env() (map[string]string, error) {
	b, err := exec.Command("brew", "--env").Output()

	if err != nil {
		return nil, err
	}

	return parseEnv(b), nil
}
Пример #3
0
func Config() (map[string]string, error) {
	b, err := exec.Command("brew", "config").Output()

	if err != nil {
		return nil, err
	}

	return parseConfig(b), nil
}
Пример #4
0
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
}
Пример #5
0
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
}
Пример #6
0
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
}
Пример #7
0
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
}
Пример #8
0
func Upgrade(name string) (string, error) {
	return exec.Command("brew", "upgrade", name).StringOutput(true)
}
Пример #9
0
func Remove(name string) (string, error) {
	return exec.Command("brew", "remove", name).StringOutput(true)
}
Пример #10
0
func Install(name string) (string, error) {
	return exec.Command("brew", "install", name).StringOutput(true)
}