Skip to content

Commit

Permalink
feat(ExTop): allow users to interactively select a Node to connect to
Browse files Browse the repository at this point in the history
This commit also removes the "-noinput" argument to escript emu_args so
that IO.gets/1 (to choose a Node) works. This might result in a warning
like:

    Port<0.2105> stealing control of fd=0 from input driver fd (0/1) #Port<0.351>

I'll fix this once I find a good workaround.

Closes #3.
  • Loading branch information
utkarshkukreti committed Nov 19, 2015
1 parent 67539f6 commit 7b5a45d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 12 additions & 1 deletion lib/ex_top.ex
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,18 @@ defmodule ExTop do
end

node = case args do
[] -> Node.self
[] ->
IO.puts "Select a Node to connect to:"
{:ok, names} = :net_adm.names
[_, host] = Node.self |> Atom.to_string |> String.split("@")
nodes = for {name, _} <- names do
String.to_atom "#{name}@#{host}"
end
for {node, index} <- nodes |> Enum.with_index do
IO.puts "#{index}: #{node}"
end
which = IO.gets("") |> String.rstrip |> String.to_integer
Enum.fetch!(nodes, which)
[node] -> String.to_atom(node)
end

Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ defmodule ExTop.Mixfile do

defp escript do
[main_module: ExTop,
emu_args: "-noinput -elixir ansi_enabled true"]
emu_args: "-elixir ansi_enabled true"]
end
end

0 comments on commit 7b5a45d

Please sign in to comment.