improve OptionParser?

130 views
Skip to first unread message

derek

unread,
Feb 21, 2016, 7:14:15 AM2/21/16
to elixir-l...@googlegroups.com
Hi, I'm a new in Erlang/Elixir with somewhat good Python background,
trying to write some small shell utils in Elixir exs script and am
surprised the OptionParser is limited and totally missing in Erlang
standard lib, I read somewhat rebar code and it's using the
`jcomellas/getopt` [3] solution, but I prefer a in lib solution,

Problems with current Elixir OptionParser:
1. it doesn't support combine switches, like "-vn" should be treated
same as "-v -n" if both are not requiring an argument;
2. I need to count behaviour like the Python argparser
`action="count"`; it will be useful to support "--verbose" or "-vvv"
to mean increased verbosity

parser.add_argument("-v", "--verbosity", action="count",
help="increase output verbosity")


[1] http://elixir-lang.org/docs/master/elixir/OptionParser.html
[2] https://github.com/elixir-lang/elixir/blob/master/lib/elixir/lib/option_parser.ex
[3] https://github.com/jcomellas/getopt
[4] https://docs.python.org/2/howto/argparse.html

I'm trying to improve OptionParser, have some local changes in
option_parser.ex, basically I hope it can be as powerful as Python
argparse module [4]; would like to see here if you have some more
ideas,


Thanks,

José Valim

unread,
Feb 21, 2016, 7:27:20 AM2/21/16
to elixir-l...@googlegroups.com
Yes, improvements to the action parser will be really welcome. Feel free to expand on your proposals here and send PRs. For example, :count could be done in the existing :switches configuration. I would also be ok with support -vn and the like.



José Valim
Skype: jv.ptec
Founder and Director of R&D


--
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/CAJctwx4P4260r0WiMD7pDScReiqwc5vg88MufVHm9hyV6mpvRA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Chris Keele

unread,
Dec 22, 2016, 9:11:42 PM12/22/16
to elixir-lang-core, jose....@plataformatec.com.br
Currently only single-letter aliases are allowed. Is this intentional or would the capacity to alias, for instance, option "foo" as "bar" be a welcome PR?

Amos King

unread,
Dec 22, 2016, 9:14:02 PM12/22/16
to elixir-l...@googlegroups.com
What is the use case?

Amos King
Binary Noggin

Chris Keele

unread,
Dec 22, 2016, 11:38:39 PM12/22/16
to elixir-lang-core
This was mostly just surprising, not problematic, behaviour.

I have switch of type :keep called :type where you can choose the type of thing to create. You can create many things in one go by passing --type foo --type bar, but it reads well when creating one thing to just say --new thing

I could unify the two syntaxes with no extra logic by aliasing :type as :new.

José Valim

unread,
Dec 23, 2016, 4:29:43 AM12/23/16
to elixir-l...@googlegroups.com
The reason only single letters are allowed is to support the sort of shortcut that's common on Unix command lines. For example, if you have two aliases named -f and -a, you can pass them as -fa. I believe we could still support multi letter aliases but probably not worth the added complexity. If you really need multi letter aliases, you can always do a prepass on the args and expand them.



José Valim
Skype: jv.ptec
Founder and Director of R&D

To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/0363554a-3df7-4e8a-bf5a-82a044321142%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages