Architectural advice for CLI tool

I’m returning to Haskell after many years and I want to write a CLI tool. Firstly, how is CLI tooling these days? One of the main reasons I have been considering Rust is much better libraries for CLI programs. There was Iris, but it’s abandoned. Other options? From a quick look I have not found anything new.

The main question is: I want an extensible architecture, which means that I want to allow plugins to be added to the program. For example, the program works with containers and I want it to work with Podman if a plugin is added or with Docker if another plugin is added.

I do not want to recompile it with Podman or Docker capabilities. For packaging and distribution, I want them to be separate packages e.g. my-program, another OS package my-program-podman, another my-program-docker etc. The main program would pass information to the additional package which would build and run a command that would then be run accordingly i.e. via Podman or Docker, then pass information back to the main program. Another example, if you use TMUX you can install an additional package my-program-tmux and that would add a subcommand my-program tmux to the main program.

Are there any examples of such architecture in Haskell, or any framework that would allow for that? So that I focus more on my program rather than solving this problem.

At a fundamental level, if you see a subcommand foo, simply look for my-program-foo on PATH. optparse-applicative is still the go-to CLI library; you’d probably add a subcommand group and fallback to a positional argument with <|>.

Yes, I think cabal does this, so you could look at that.

hledger also does it, and is probably the best example you’ll find of trying to make it seamless and ergonomic, with consistent command line UX across the core program and the subprograms. Be warned, not a simple task..

(Separate executables aren’t as plugged-in as traditional plugins, so I call them addon commands).

Check Hackage for the available command line-parsing libs. Usually there are two full-featured contenders: optparse-applicative and cmdargs.

Yeah, I think that would be the most realistic approach, thank you both for the suggestions! I’ll be looking into the cabal and hledger source code. I’ve used both optparse-applicative and cmdargs in the past so I should be good there too.