Phillipp

Phillipp

OptionParser alias behavior

Hey,

I am building a CLI tool and use the OptionParser module to parse the arguments.

Now I got a --config-override option which accepts a string. I also wanted to have a -co short version (alias). So this was my initial configuration:

    {switches, _, _} = OptionParser.parse(
      args,
      switches: [
        config_override: :string
      ],
      aliases: [
        co: :config_override
      ]
    )

But then, at runtime, I got a warning:

warning: multi-letter aliases are deprecated, got: :co

Fine, I then changed the alias to just -o:

    {switches, _, _} = OptionParser.parse(
      args,
      switches: [
        config_override: :string
      ],
      aliases: [
        o: :config_override
      ]
    )

The weird behavior I experience is, that not only -o works but also -co. Where does the -co come from?

Marked As Solved

amarraja

amarraja

I’m not familiar with the option parser module, however in shell convention -co is shorthand for -c -o - that is why they can only be single letters.

In your case, -o is activating the switch, and -c is probably just getting ignored

Also Liked

Phillipp

Phillipp

Ah, that might explain it. So the module seems to implement that convention as well.

iex(48)> args = ["-co", "foo"]
["-co", "foo"]
iex(49)> {switches, _, _} = OptionParser.parse(
...(49)>       args,
...(49)>       switches: [
...(49)>         debug: :boolean,
...(49)>         config_override: :string
...(49)>       ],
...(49)>       aliases: [
...(49)>         o: :config_override
...(49)>       ]
...(49)>     )
{[config_override: "foo"], [], [{"-c", nil}]}

As you said, -c is ignored.

Where Next?

Popular in Questions Top

pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
sabri
Can someone explain the settings of pool_size of Ecto in config file? and what is the recommend size? Thanks
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

Other popular topics Top

chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30048 115
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1140 51847 244
New
Tee
can someone please explain to me how Enum.reduce works with maps
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 35421 110
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New

We're in Beta

About us Mission Statement