Brandon Gillespie
unread,Apr 29, 2023, 12:00:57 PM4/29/23Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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