Library for building command line interfaces in Erlang

Hi guys,

I’ve my Erlang service perfectly running and I’d like to add an admin console to it.
I found clique but couldn’t get my head around it.
It seems a bit complicated and I’m looking for something simple to manage.
There is also ectl. But it wasn’t updated for the last +10y.

For example, I’d like to be able to add/delete/update user account in my app.
@max-au argparse could be a good start.

Help appreciated.
Z.

argparse is in the stdlib as of OTP/26

2 Likes

Screenshot 2023-09-08 at 21.22.47

I think argpase plus an Erlang library which can list data in a tabular way (see attached screenshot) could solve my problem.

1 Like

Alternatively, you can use GitHub - k32/Lee: THIS IS A WORK OF FICTION AND NOT an extensible, self-documenting, type-safe configuration manager for Erlang , it’ll cover not just CLI parsing, but the rest of the configuration needs as well.
A real-world example using this library: GitHub - emqx/emqttb: A scriptable autotuning load generator for MQTT

Fun fact, argparse was originally a part of a larger library intended to perform exactly the task you’re after. And cli module (cli.erl) is the code enabling such functionality.

I use it in the following combination:

  • my service code has multiple modules implementing -behaviour(cli).
  • a very small trampoline escript that simply runs rpc:call('node@hostname', cli, run, init:get_all_arguments(), #{modules => all_loaded})

How it works: my primary service is running in a context of a production node. It has many modules loaded, and exporting cli callback. The trampoline script effectively just passes the command line invocation (via rpc) to that service.

6 Likes

@max-au Amazing. This is exactly what I’m looking for. I gonna use your cli example as a base for my project. Thanks a lot.

@max-au are you aware of any Erlang library which can list data in a tabular way (see above screenshot)?

Not that I heard of, but given how simple the code is, I just copy-and-paste lines doing that job from one project to another. To a degree that I’m not sure whether it’s worth having it in the OTP itself.

1 Like

https://github.com/eproxus/grid

5 Likes

Thanks @LeonardB

There’s also GitHub - mbj4668/eclip: Erlang command line parser, which is inspired by Pyhton’s click. Supports tab-completion for bash and zsh.

1 Like

I used GitHub - rabbitmq/stdout_formatter: Erlang library to format paragraphs, lists and tables as plain text
Works fine.

3 Likes

Grid is pretty simple as of now. Let me know if you have any feature requests :blush:

1 Like