zoedsoupe
What would be the most idiomatic way to declare CLI cmds using a library?
If you were using a CLI library in elixir, do you prefer to use the module and then each function defined generates a CLI cmd or do you prefer to have define macros cmds and handle events for each cmd? examples below
option 1, with using macro and “native” definition using only module attributes:
option 2, with “define” macros and events
I didn’t find any decent library to build CLI commands and options ala rust clap or clojure clapps, so I would like to build my own to Elixir. It will probably leverage the owl package “components” in the future, but firstly I would like to see opinions of the usage proposals!
Most Liked
zachallaun
My recommendation is to start with an option 3: pure data description and manual composition/function calls with no magic. You can add a convenience layer on top after you have a very clear idea of how things should compose and be organized.
Edit: I’d look at NimbleOptions for API inspiration.
dimitarvp
While I will not address your questions directly, I just want to make sure you’re aware of Owl - A toolkit for writing command-line user interfaces by @fuelen.
dimitarvp
I see. To be fair Rust’s clap has quite a lot of magic. Try something more manual and explicit for the first iteration IMO.
Popular in Discussions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance
![defmodule MyCLI do use Nexus @doc """ Answers "fizz" on "buzz" input and vice-versa """ @cmd_type {:enum, ["fizz", "buzz"]} @required true def fizzbuzz(input) do # logic... end end](https://forum.elixirforum.com/uploads/default/original/3X/8/c/8cdc1008d435b0f8451384d952b033604797c9b3.jpeg)









