   Module responsible for controlling Elixir's CLI
   """
 
-  defrecord Config, commands: [], output: ".",
-                    compile: [], halt: true, compiler_options: []
+  defrecord Config, commands: [], output: ".", compile: [],
+                    halt: true, compiler_options: [], errors: []
 
   # This is the API invoked by Elixir boot process.
   @doc false

  defp process_shared(["-r",h|t], config) do
    files = Path.wildcard(h)
    if files == [] do
      IO.puts(:stderr, "-r : No files matched pattern #{h}")
      System.halt(1)
    else
      process_shared t, Enum.reduce(files, config, fn path, config ->
        config.update_commands [{:require,path}|&1]

    :elixir_code_server.cast({ :argv, argv })

    run fn ->
      command_results = Enum.map(Enum.reverse(config.commands), process_command(&1, config))
      command_errors  = Enum.filter_map(command_results, &1 != :ok, fn {:error, msg} -> msg end)
      errors          = Enum.reverse(config.errors) ++ command_errors
      if errors != [] do
        Enum.each(errors, fn msg -> IO.puts(:stderr, msg) end)
        System.halt(1)
      end
    end, config.halt
  end

