Skip to content

Commit

Permalink
Print out nice message when not loaded
Browse files Browse the repository at this point in the history
It turns out to be pretty easy to run `VintageNet.info` before
`VintageNet` is loaded if you're impatient. I do this regularly. This
makes it print a nice message rather than raising an exception in
`elem/2`.
  • Loading branch information
fhunleth committed Feb 5, 2020
1 parent e0ba08c commit 9710fbd
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions lib/vintage_net/info.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,19 @@ defmodule VintageNet.Info do
"""
@spec info([VintageNet.info_options()]) :: :ok
def info(opts \\ []) do
version = :application.loaded_applications() |> List.keyfind(:vintage_net, 0) |> elem(2)
case version() do
:not_loaded ->
IO.puts("VintageNet hasn't been loaded yet. Try again soon")

IO.write("""
VintageNet #{version}
version ->
IO.puts(["VintageNet ", version])

do_info(opts)
end
end

defp do_info(opts) do
IO.write("""
All interfaces: #{inspect(VintageNet.all_interfaces())}
Available interfaces: #{inspect(VintageNet.get(["available_interfaces"]))}
""")
Expand All @@ -32,6 +40,15 @@ defmodule VintageNet.Info do
end
end

defp version() do
Application.loaded_applications()
|> List.keyfind(:vintage_net, 0)
|> case do
{:vintage_net, _description, version} -> version
_ -> :not_loaded
end
end

defp print_config(ifname, prefix, opts) do
configuration = VintageNet.get_configuration(ifname)

Expand Down

0 comments on commit 9710fbd

Please sign in to comment.