Recommendations to create a CLI tool

Hello. I want to star a new project in ocaml. It is going to be a CLI tool. I want it to be as user friendly as possible , as interactive as possible (lists of options to select, lots of visual aids etc) and I want it to be cross platform. It is going to have a lot of file and text manipulation.
Which template and libraries do you recommend me to start ?

Ideally I want the libraries takinf care of the differences between os (temp files location, path separator, etc).



These particular things are covered by the Filename module from the standard library.


If it will have lots of OS-command-line-level arguments and options, cmdliner will be your friend.


Cmdliner is one of the candidates, sure.
I’m also looking at Nottui and Lwd, pastel and file context printer.
Anything else you want to recommend ?

1 Like

Ah, you’re wanting to build a UI application. I thought you wanted command-line. Sorry for the misunderstanding.

All those libraries are for the command line. I want to build a cmd line tool, but I wanr it to also have rich cisual representations when needed

I asked a similar question recently at Parsing one's own command line (at least for one of the bricks you envision). Some answers there may help. Actually, Cmdliner can parse not only the command line, but any string array: see the documentation for the argument argv in

val eval : ?help:Stdlib.Format.formatter -> ?err:Stdlib.Format.formatter ->
 ?catch:bool -> ?env:(string -> string option) -> ?argv:string array ->
 ?term_err:Exit.code -> unit t -> Exit.code

I’d recommend to read some code of similar projects, and I’d like to do so myself, but I haven’t found many. I looked at the way the interface of utop was coded, to get some inspiration.

One difference between “parsing one’s command line” and “a CLI tool” is that in the former case, you need to

  1. know when the “line” ends – that is, whether it’s been continued onto subsequent lines. This isn’t trivial if you decide to add multi-line raw strings and such to your cmdline language.
  2. once you have your line terminated, you have to be able to break it into tokens – at the very least, know when quoted tokens start and end.
  3. know how to evaluate a quotation to produce a “value”, so that “ab\ncd” is equal to the one with an actual linefeed. And perhaps ‘ab’‘cd’ is equal to “abcd” and to ‘abcd’. This will also remove the quotations,unescaping any special characters.
  4. And finally then, you can hand your string to cmdliner (or to Arg for that matter).

All of the above, is what your shell does for you.

Not sure if you are answering me or the message above, but I never had the intention to build anything like a repl/command line.
The reason why I’m lookig at “graphical” cmd tools is because, when needed, I prefer to offer the user a list of “checkboxes” to pick from ratuer than failing and showing a message requesting a list of options and make the user type them.

Just a note on terminology to help with clarity: CLI stands for “command line interface”, which entails that the interface for providing input into the program is a line in which commands are written. This is what Cmdliner handles. Iiuc you are looking to develop a text user interface, also known as a TUI.

I’ve enjoyed working with Notty before on toy projects. For file systems and OS interaction I recommend Bos.


Maybe that could be of some help:

1 Like