Escript changes behavior of functions?

I am new to elixir and I decided to learn it by writing a small CLI app for personal use. I use the OptionParser module to parse the passed parameters, so I have this function:

      def main(arguments) do
        arguments
        |> execute_function
      end

      defp execute_function(["run" | params]) do
        IO.inspect params
        {opts,a,b}= OptionParser.parse(
          params,
          aliases: [d: :db_name],
          switches: [db_name: :string])
        |> IO.inspect
      end

if i call it from iex:

iex(1)> Potion.CLI.main(["run", "-d", "test", "--dev=qweb,xml"])
["-d", "test", "--dev=qweb,xml"]
{[db_name: "test", dev: "qweb,xml"], [], []}
{[db_name: "test", dev: "qweb,xml"], [], []}

everything is fine and works as expected. If i build it with escript though:

$ rm -rf potion && mix escript.build
Generated escript potion with MIX_ENV=dev

$ ./potion run -d test --dev=xml,qweb
["-d", "test", "--dev=xml,qweb"]
{[db_name: "test"], [], []}

So the question is: is it a bug or am I missing something?

P.S.
Elixir - 1.7.3
erlang-nox - 21.1.3

Okay, after a little bit of research and docs reading - OptionParser says that this behaviour can be possible here
so passing the key allow_nonexistent_atoms solves the issue I had. Can be locked and marked as answered. I am sorry :frowning:

2 Likes

You can mark as answered on your own, just click the boxed checkmark below the post that answers the question. You might need to expand the posts options first by clicking on the three dots. I’ll mark your post as the answer in the meantime.