Skip to content

Commit

Permalink
Attempt to simplify logic
Browse files Browse the repository at this point in the history
  • Loading branch information
msoedov committed May 17, 2017
1 parent bcbfff4 commit cb51817
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions lib/firex.ex
Original file line number Diff line number Diff line change
Expand Up @@ -81,26 +81,32 @@ defmodule Firex do
end
end

defp help(cm, help_info) do
msg = cm |> Enum.map(fn {name, params} ->
signature = params
|> Keyword.get(:aliases, [])
|> Enum.zip(Keyword.get(params, :switches, []))
|> Enum.map(fn {{k, v}, {_, type}} -> "-#{k} --#{v} <#{v}:#{type}>" end)
|> Enum.join(", ")

meta = Map.get(help_info, name, {nil, nil})
{doc, _} = meta
desc = case String.length(signature) do
0 -> "no args required"
_ -> signature
end
"""
#{name}: #{desc}
#{doc}
"""
end) |> Enum.join("\n")
defp command_help(name, params, help_info) do
switches = Keyword.get(params, :switches, [])
signature = params
|> Keyword.get(:aliases, [])
|> Enum.zip(switches)
|> Enum.map(fn {{k, v}, {_, type}} -> "-#{k} --#{v} <#{v}:#{type}>" end)
|> Enum.join(", ")

meta = Map.get(help_info, name, {nil, nil})
{doc, _} = meta

desc = case String.length(signature) do
0 -> "no args required"
_ -> signature
end
"""
#{name}: #{desc}
#{doc}
"""
end

defp help(command_map, help_info) do
msg = command_map
|> Enum.map(fn {name, params} -> command_help(name, params, help_info) end)
|> Enum.join("\n")

IO.puts """
#{pub_moduledoc}
Expand Down

0 comments on commit cb51817

Please sign in to comment.