Esempio n. 1
0
// Search builds a search URL and opens it in your browser.
func Search(p string, q string, verbose bool) {
	builder := Providers[p]

	if builder != nil {
		url := builder.BuildURI(q)
		if verbose {
			fmt.Printf("%s\n", url)
		}
		launcher.OpenURI(url)
	} else {
		fmt.Printf("Provider %q not supported!\n", p)
	}
}
Esempio n. 2
0
// Search builds a search URL and opens it in your browser.
func Search(binary string, p string, t string, q string, userProvider bool, outputOnly bool, verbose bool) error {
	prov, err := ExpandProvider(p)
	if err != nil {
		return err
	}

	builders := []Provider{}

	if t == "" || userProvider {
		builders = append(builders, Providers[prov])
	}

	if t != "" {
		tag, err := ExpandTag(t)
		if err != nil {
			return err
		}

		builders = append(builders, GetProvidersByTag(tag)...)
	}

	var success bool

	for _, builder := range builders {
		if builder != nil {
			url := builder.BuildURI(q)

			if verbose || outputOnly {
				fmt.Printf("%s\n", url)
			}

			if !outputOnly {
				err = launcher.OpenURI(binary, url)
				if err != nil {
					return err
				}
			}

			success = true
		}
	}

	if !success {
		return fmt.Errorf("No providers found for tag %q.", t)
	}

	return nil
}
Esempio n. 3
0
// Search builds a search URL and opens it in your browser.
func Search(binary string, p string, q string, verbose bool) error {
	prov, err := ExpandProvider(p)
	if err != nil {
		return err
	}

	builder := Providers[prov]

	if builder != nil {
		url := builder.BuildURI(q)

		if verbose {
			fmt.Printf("%s\n", url)
		}

		return launcher.OpenURI(binary, url)
	}

	return fmt.Errorf("Provider %q not supported!\n", prov)
}