     end
   end
 
+  # This splits the list of arguments with the command name already stripped
   defp split(args) when is_binary(args) do
     String.split args, " "
-  end
-
-  defp open_port(opts) do
-    go = :os.find_executable 'go'
-    Port.open { :spawn_executable, go }, opts
-  end
-
-  defp init_port_connection(cmd, args, options) do
-    port = open_port(port_options(options, cmd, args))
-
-    input  = process_input_opts(port, options[:in])
-    output = process_output_opts(port, options[:out])
-    error  = process_error_opts(port, options[:err])
-
-    { port, input, output, error }
   end
 
   @doc """

    port_opts
  end

  defp process_input_opts(_port, opt) do
    case opt do
      nil          -> nil
      :pid         -> :something # TODO: spawn(...)
      { :file, f } -> { :file, f }
      bin when is_binary(bin) ->
        bin
        ## TODO: make it async
        #Port.command(port, bin)
        #nil
    end
  end

  defp process_output_opts(_port, opt) do
    case opt do
      nil          -> { :buffer, nil }
      :err         -> nil
      :buffer      -> { :buffer, nil }
      { :file, f } -> { :file, f }
      pid when is_pid(pid) ->
        pid
    end
  end

  defp process_error_opts(_port, opt) do
    case opt do
      nil          -> { :buffer, nil }
      :out         -> nil
      :buffer      -> { :buffer, nil }
      { :file, f } -> { :file, f }
      pid when is_pid(pid) ->
        pid
    end
  end


  defp flatten(nil) do
    ""
  end

  defp flatten(list) do
    flatten(list, [])
  end

  defp flatten([], acc) do
    acc |> Enum.reverse |> Enum.join("")
  end

  defp flatten([ [] | t ], acc) do
    flatten(t, acc)
  end

  defp flatten([ [h|t] | tt ], acc) do
    flatten([ t | tt ], [h|acc])
  end

  defp flatten([ h | t ], acc) do
    flatten(t, [h|acc])
  end
end


                     #out: :err | :buffer | pid | {:file, ...},
                     #err: :out | :buffer | pid | {:file, ...})

#Porc.call("cat", in: "Hello world!")
# ==>
#p = Port.open({:spawn_executable, '/usr/local/bin/go'}, [{:args, ["run", "main.go", "cat"]}, :binary, {:packet, 2}, :exit_status])

