wishlist: macro/modern argparser

39 views
Skip to first unread message

Brandon Gillespie

unread,
Apr 29, 2023, 12:00:57 PM4/29/23
to elixir-l...@googlegroups.com
I realize CLI tooling isn't elixir's focus, but what I'd give for a nice
argparser!

Something in-code like python's argparser would be phenomenal, which
handles syntax and user experience for you. I think it wouldn't be hard,
with macros:

```

defmodule MyParser do
  use ArgParser

  parser do
    command("d?hcp") do
      command("l?ist|ls") do
        option("--all|-a", :boolean, store: true)
        option("--mon?itor|-m", :boolean, store: true)
      end
    end

    command "g?enerate" do
      option("--f?orce|-f", :boolean, store: true)
      command("w?edge") do
         argument("slot", :integer, choices: [0, 1])
         option("--r?restart|-r", :boolean, store: true)
      end
    end
  end
```

Then just `MyParser.parse(args)`

I hear erlang's "argparse" is coming into OTP, but I haven't looked at
it. I expect like most things erlang it's highly eldritch :D

I'll add it to the end of my todo list, just after ∞ unfortunately. But
maybe I'll get to it.

Sidebar to this:

I know Elixir isn't focused on CLI, and there are few if any CLI things
out there, but I'd contend it's a chicken-and-egg thing. There aren't
CLI things out there because it's such a PITA to do it (having just
wrestled with escript and others trying to do this I can assure you this
is the case). I've seriously considered wrapping my elixir thing with a
python script, just to make it more user-friendly and manageable.
That's... well, it says something.

-Brandon

Zach Daniel

unread,
Apr 29, 2023, 12:36:38 PM4/29/23
to elixir-l...@googlegroups.com
You could consider using Spark :)

Its used for Ash Framework, as well as ChannelHandler: 

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/d969eddb-c7bf-8cf8-99ee-c4fa16a5f52e%40cold.org.

José Valim

unread,
Apr 29, 2023, 3:48:11 PM4/29/23
to elixir-l...@googlegroups.com
+1 for more tools for working with CLIs but that's definitely outside of the scope of the language itself. For more information, we have a document on the development guidelines and team: https://elixir-lang.org/development.html - Discussions about additional tooling to the ecosystem are probably better suited to ElixirForum, because a wider community will be able to jump in and participate.

Reply all
Reply to author
Forward
0 new messages