Example #1
0
func (p *BrewProvider) Install(arg ...string) error {
	cmd := cmd.Command("brew", append([]string{"install"}, arg...)...)
	if err := cmd.Start(); err != nil {
		return err
	}
	defer cmd.Wait()
	scanner := cmd.Scanner()
	for scanner.Scan() {
		log.Printf("[brew] %s", scanner.Text())
		if err := scanner.Err(); err != nil {
			return err
		}
	}
	return nil
}
Example #2
0
func (p *BrewProvider) Search(arg ...string) ([]string, error) {
	cmd := cmd.Command("brew", append([]string{"search"}, arg...)...)
	if err := cmd.Start(); err != nil {
		return nil, err
	}
	defer cmd.Wait()
	matches := []string{}
	scanner := cmd.Scanner()
	for scanner.Scan() {
		line := scanner.Text()
		line = strings.Replace(line, " (installed)", "", -1)
		log.Printf("[brew] %s", line)
		matches = append(matches, line)
	}
	return matches, nil
}
Example #3
0
func (p *NpmProvider) getCache() (string, error) {
	cmd := cmd.Command("npm", "--no-color", "config", "get", "cache")
	if err := cmd.Start(); err != nil {
		return "", err
	}
	defer cmd.Wait()
	scanner := cmd.Scanner()
	if scanner.Scan() {
		path := strings.Trim(scanner.Text(), "\n\r")
		log.Printf("[npm] %s", path)
		return path, nil
	}
	if err := scanner.Err(); err != nil {
		return "", err
	}
	return "", os.ErrNotExist
}
Example #4
0
func searchNpm(arg ...string) ([]string, error) {
	cmd := cmd.Command("npm", append([]string{"--no-color", "search"}, arg...)...)
	if err := cmd.Start(); err != nil {
		return nil, err
	}
	defer cmd.Wait()
	matches := []string{}
	scanner := cmd.Scanner()
	for scanner.Scan() {
		line := scanner.Text()
		if !strings.HasPrefix(line, "NAME") {
			if index := strings.Index(line, " "); index > 0 {
				match := line[0:index]
				log.Printf("[npm] %s", match)
				matches = append(matches, match)
			}
		}
	}
	return matches, nil
}
Example #5
0
func (p *YumProvider) Search(arg ...string) ([]string, error) {
	cmd := cmd.Command("yum", append([]string{"search", "--quiet"}, arg...)...)
	if err := cmd.Start(); err != nil {
		return nil, err
	}
	defer cmd.Wait()
	matches := []string{}
	scanner := cmd.Scanner()
	for scanner.Scan() {
		line := scanner.Text()
		if strings.HasPrefix(line, "=") || strings.HasPrefix(line, " ") {
			continue
		}
		if index := strings.Index(line, " "); index > 0 {
			match := line[0:index]
			log.Printf("[yum] %s", match)
			matches = append(matches, match)
		}
	}
	return matches, nil
}