<commit_before>defmodule ElixirScript.CLI do
  @moduledoc false

  @switches [
    output: :binary, elixir: :boolean, root: :binary,
    help: :boolean, stdlib: :boolean, stdlib_path: :binary
  ]

  @aliases [
    o: :output, ex: :elixir, h: :help, r: :root, st: :stdlib, stp: :stdlib_path
  ]

  def main(argv) do
    argv
    |> parse_args
    |> process
  end

  def parse_args(args) do
    parse = OptionParser.parse(args, switches: @switches, aliases: @aliases)

    case parse do
      { [help: true] , _ , _ } -> :help
      { [stdlib: true] , _ , _ } -> :stdlib
      { options , [input], _ } -> { input, options }
      _ -> :help
    end

  end

  def process(:help) do
    IO.write """
      usage: elixirscript <input> [options]
      <input> path to elixir files or
              the elixir code string if the -ex flag is used
      options:
      -o  --output [path]   places output at the given path
      -ex --elixir          read input as elixir code string
      -r  --root [path]     root import path for all exported modules
      -st  --stdlib         outputs the standard lib js file
      -stp --stdlib_path    es6 import path to the elixirscript standard lib
      only used with the [output] option. When used, Elixir.js is not exported
      -h  --help            this message
    """
  end

  def process(:stdlib) do
    IO.write(ElixirScript.standard_libs)
  end

  def process({ input, options }) do
    if options_contains_unknown_values(options) do
        process(:help)
    else
        do_process(input, options)
    end
  end

  def do_process(input, options) do
    compile_opts = %{
      root: options[:root],
      include_path: options[:output] != nil,
      stdlib_path: Keyword.get(options, :stdlib_path, "Elixir")
    }

    compile_output = case options[:elixir] do
      true ->
        ElixirScript.compile(input, compile_opts)
      _ ->
        ElixirScript.compile_path(input, compile_opts)
    end

    case options[:output] do
      nil ->
        Enum.map(compile_output,
          fn
          ({_path, code})-> code
          (code)-> code
        end)
        |> IO.write
      output_path ->
        Enum.each(compile_output, fn(x) ->
          write_to_file(x, output_path)
        end)

        if options[:stdlib_path] == nil do
          ElixirScript.copy_standard_libs_to_destination(output_path)
        end
    end
  end<commit_msg>Added file delimiters for standard output<commit_after>defmodule ElixirScript.CLI do
  @moduledoc false

  @switches [
    output: :binary, elixir: :boolean, root: :binary,
    help: :boolean, stdlib: :boolean, stdlib_path: :binary
  ]

  @aliases [
    o: :output, ex: :elixir, h: :help, r: :root, st: :stdlib, stp: :stdlib_path
  ]

  def main(argv) do
    argv
    |> parse_args
    |> process
  end

  def parse_args(args) do
    parse = OptionParser.parse(args, switches: @switches, aliases: @aliases)

    case parse do
      { [help: true] , _ , _ } -> :help
      { [stdlib: true] , _ , _ } -> :stdlib
      { options , [input], _ } -> { input, options }
      _ -> :help
    end

  end

  def process(:help) do
    IO.write """
      usage: elixirscript <input> [options]
      <input> path to elixir files or
              the elixir code string if the -ex flag is used
      options:
      -o  --output [path]   places output at the given path
      -ex --elixir          read input as elixir code string
      -r  --root [path]     root import path for all exported modules
      -st  --stdlib         outputs the standard lib js file
      -stp --stdlib_path    es6 import path to the elixirscript standard lib
      only used with the [output] option. When used, Elixir.js is not exported
      -h  --help            this message
    """
  end

  def process(:stdlib) do
    IO.write(ElixirScript.standard_libs)
  end

  def process({ input, options }) do
    if options_contains_unknown_values(options) do
        process(:help)
    else
        do_process(input, options)
    end
  end

  def do_process(input, options) do
    compile_opts = %{
      root: options[:root],
      include_path: true,
      stdlib_path: Keyword.get(options, :stdlib_path, "Elixir")
    }

    compile_output = case options[:elixir] do
      true ->
        ElixirScript.compile(input, compile_opts)
      _ ->
        ElixirScript.compile_path(input, compile_opts)
    end

    case options[:output] do
      nil ->
        Enum.map(compile_output,
          fn
          ({path, code})-> "//#{path}:ENDFILENAME\n" <> code
        end)
        |> Enum.join("//:ENDFILE\n")
        |> IO.write
      output_path ->
        Enum.each(compile_output, fn(x) ->
          write_to_file(x, output_path)
        end)

        if options[:stdlib_path] == nil do
          ElixirScript.copy_standard_libs_to_destination(output_path)
        end
    end
  end
{'fraction_non_alphanumeric': 0.1063610078479967, 'fraction_numerical': 0.0004130524576621231, 'mean_word_length': 2.1695026178010473, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2609630', 'n_tokens_mistral': 1603, 'n_tokens_neox': 1534, 'n_words': 443}