Style-guide compliance.

This commit is contained in:
Brandon Shroyer 2016-02-02 16:26:10 -05:00
parent 2775ed5a82
commit a843b837d8
4 changed files with 27 additions and 27 deletions

View File

@ -4,13 +4,13 @@ defmodule CLI do
import StatusCommand
def main(command) do
unless Node.alive?(), do: :net_kernel.start([:rabbitmqctl, :shortnames])
:net_kernel.start([:rabbitmqctl, :shortnames])
{parsed_cmd, options} = parse(command)
case options[:node] do
nil -> IO.puts connect_to_rabbitmq()
_ -> IO.puts connect_to_rabbitmq(String.to_atom(options[:node]))
nil -> connect_to_rabbitmq |> IO.puts
_ -> options[:node] |> String.to_atom |> connect_to_rabbitmq |> IO.puts
end
run_command(parsed_cmd, options)
@ -18,7 +18,7 @@ defmodule CLI do
end
defp print_nodedown_error(options) do
target_node = options[:node] || get_rabbit_hostname()
target_node = options[:node] || get_rabbit_hostname
IO.puts "Status of #{target_node} ..."
IO.puts "Error: unable to connect to node '#{target_node}': nodedown"
@ -26,8 +26,8 @@ defmodule CLI do
defp run_command(["status"], options) do
case result = status(options) do
{:badrpc, :nodedown} -> print_nodedown_error(options)
_ -> print_status(result)
{:badrpc, :nodedown} -> print_nodedown_error(options)
_ -> print_status(result)
end
end
end

View File

@ -1,8 +1,10 @@
defmodule Helpers do
def get_rabbit_hostname(), do: "rabbit@" <> hostname() |> String.to_atom()
@rabbit_host "rabbit"
def connect_to_rabbitmq(), do: :net_kernel.connect_node(get_rabbit_hostname())
def get_rabbit_hostname(), do: (@rabbit_host <> "@" <> hostname) |> String.to_atom
def connect_to_rabbitmq(), do: :net_kernel.connect_node(get_rabbit_hostname)
def connect_to_rabbitmq(input), do: :net_kernel.connect_node(input)
defp hostname(), do: elem(:inet.gethostname,1) |> List.to_string()
defp hostname(), do: :inet.gethostname() |> elem(1) |> List.to_string
end

View File

@ -9,6 +9,7 @@ defmodule Parser do
{clear_on_empty_command(cmd), options}
end
# Discards entire command if first command term is empty.
defp clear_on_empty_command(command_args) do
case command_args do
[] -> []

View File

@ -6,18 +6,19 @@ defmodule StatusCommand do
def status(options) do
case options[:node] do
nil -> :rpc.call(get_rabbit_hostname(), :rabbit, :status, [])
host when is_atom(host) -> :rpc.call(host, :rabbit, :status, [])
host when is_binary(host) -> :rpc.call(String.to_atom(host), :rabbit, :status, [])
nil -> get_rabbit_hostname |> :rpc.call(:rabbit, :status, [])
host when is_atom(host) -> host |> :rpc.call(:rabbit, :status, [])
host when is_binary(host) -> host |> String.to_atom() |> :rpc.call(:rabbit, :status, [])
end
end
def print_status(result) do
result |>
print_pid |>
print_running_apps
result
|> print_pid
|> print_running_apps
end
defp print_pid(result) when not is_list(result), do: result
defp print_pid(result) when is_list(result) do
case result[:pid] do
nil -> nil
@ -26,26 +27,22 @@ defmodule StatusCommand do
result
end
defp print_pid(result) when not is_list(result) do
result
end
defp print_running_apps(result) when not is_list(result), do: result
defp print_running_apps(result) when is_list(result) do
IO.puts "Applications currently running:"
IO.puts "---------------------------------------"
case result[:running_applications] do
nil -> nil
_ -> Enum.map(
result[:running_applications],
fn ({id, name, version}) -> :io.format("~-#{@id_length}s | ~-#{@name_length}s | ~s\n", [id, name, version])
_ -> result[:running_applications] |> Enum.map(
fn ({id, name, version}) ->
:io.format(
"~-#{@id_length}s | ~-#{@name_length}s | ~s\n",
[id, name, version]
)
end
)
)
end
result
end
defp print_running_apps(result) when not is_list(result) do
result
end
end