Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions lib/mix/tasks/hex.search.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ defmodule Mix.Tasks.Hex.Search do
### Options

* `--organization ORGANIZATION` - Set this for private packages belonging to an organization
* `--print-url` - Print the docs URL instead of opening it in the browser

"""
@behaviour Hex.Mix.TaskDescription

@switches [organization: :string, package: :string, stdlib: :boolean]
@switches [organization: :string, package: :string, stdlib: :boolean, print_url: :boolean]

@impl true
def run(args) do
Expand Down Expand Up @@ -94,7 +95,13 @@ defmodule Mix.Tasks.Hex.Search do
|> Enum.join(",")
|> URI.encode_www_form()

Hex.Utils.system_open("https://hexdocs.pm/?packages=#{packages}&q=")
url = "https://hexdocs.pm/?packages=#{packages}&q="

if opts[:print_url] do
Hex.Shell.info(url)
else
Hex.Utils.system_open(url)
end
end

defp package_search(package, organization) do
Expand Down
19 changes: 19 additions & 0 deletions test/mix/tasks/hex.search_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,25 @@ defmodule Mix.Tasks.Hex.SearchTest do
end)
end

test "--print-url" do
Mix.Project.push(SearchDeps.MixProject)

in_tmp(fn ->
write_search_deps()
Mix.Tasks.Hex.Search.run(["--print-url"])
assert_received {:mix_shell, :info, ["https://hexdocs.pm/?packages=" <> packages]}

vsn = System.version()

assert packages =~
URI.encode_www_form(
"bar:0.1.0,eex:#{vsn},elixir:#{vsn},ex_unit:#{vsn},foo:0.1.0"
)

assert String.ends_with?(packages, "&q=")
end)
end

defp write_search_deps do
set_home_tmp()
Mix.Dep.Lock.write(%{foo: {:hex, :foo, "0.1.0"}, bar: {:hex, :bar, "0.1.0"}})
Expand Down
Loading