brew search
There are a number of websites that allow you to search for Homebrew packages, such as Braumeister. With Homebrew itself, this is done with brew search
:
brew search
- lists all locally available formula files (i.e., the ones that live in the Taps you’ve installed on your system).
brew search <text>
- returns a list of formula names that match the search term.
- For example,
brew search audio
currently yields six search results: audiofile, dromeaudio, portaudio, pulseaudio, rt-audio, and switchaudio-osx.
brew search /text/
- returns a list of formula names that match the regular expression.
brew search /.+audio.+/
yields only switchaudio-osx.
brew search --desc (<text>|/text/)
- returns a list of formulae with descriptions matching the search term.
- For example,
brew search --desc music
currently returns 27 formulae and their descriptions:
brew search (
--debian
|
--fedora
|
--fink
|
--macports
|
--opensuse
|
--ubuntu
)<text>
- performs a search for the search term on the given package manager’s website.
- For example,
brew search --ubuntu abc
navigates your web browser to this page.
brew search
didn’t have an integration test when I found it. My new test boosted its coverage from 16% to 71% (yay), though a big chunk of its behavior still remains untested (boo). Oh well. In the new test, a formula file is written to the Homebrew/homebrew-core
tap (in the exact same way that it’s done in several other integration tests, e.g., for brew home
and brew log
). As is done in the test for brew desc
, it makes the same assertions that the desc_cache.json
file is created during the course of the test (this time, when the --desc
flag is passed to brew search
). It also asserts that testball
(the test formula file) is a search result for these four calls to brew search
:
brew search
brew search testball
brew search homebrew/homebrew-core/testball
brew search --desc Some test
It then proceeds to test these lines in cmd/search.rb
. Like brew home
, brew search
employs Homebrew’s exec_browser
utility method to navigate your web browser to the desired path. An efficient, DRY way to test the six different flags is to create a single hash and then iterate over the hash to make the relevant assertions:
- the hash associates each flag with its URL.
- inside the
each...do
block, each call to thecmd
helper method sets theHOMEBREW_BROWSER
environment variable equal toecho
(just like in the test forbrew home
). - an assertion is made for each flag.
- e.g.,
brew search --debian testball
should spit out the string for this webpage.
- e.g.,
- at the end of test, as usual, the newly created files are removed from existence.