Factor out ag/format-command from ag/search.