Skip to content

CLI cannot accept a path input, though its help and the compiler both support one #501

Open

Description

@dajiaohuang

The CLI help advertises a path input:

usage: elixirscript <module | path> [options]
<path> the path to .ex(s) files to compile

ElixirScript.Compiler.compile/2 does support it — def compile(path, opts) when is_binary(path) plus the Path.wildcard/1 handling was added by #420 — but the CLI never passes a path through, because handle_input/1 maps every argument token through Module.concat/1:

defp handle_input(input) do
  input
  |> Enum.map(fn x -> String.split(x, [" ", ","], trim: true) end)
  |> List.flatten()
  |> Enum.map(fn x -> Module.concat([x]) end)
end

(lib/elixir_script/cli.ex:91-96)

So a path becomes an atom, the when is_binary(path) clause is unreachable from the CLI, and the compile aborts:

$ mix run -e 'ElixirScript.CLI.process({["test/fixtures/list_ops.ex"], []})'
[warn] ElixirScript: :"Elixir.test/fixtures/list_ops.ex" is missing or unavailable
** (MatchError) no match of right hand side value: nil
    lib/elixir_script/passes/find_used_functions.ex:36: ElixirScript.FindUsedFunctions.walk_module/2

Passing the same path straight to the compiler works, so only the CLI wiring is missing.

Reproduced on cc8a08a with Elixir 1.11.4 / OTP 23.

Filed as an issue rather than a PR because a fix needs a disambiguation rule: a bare token can be either a module name or a relative path (Atom vs ./Atom, my/path vs My.Path), so "treat it as a path when it names an existing file or directory" is a behaviour change worth agreeing on first.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions