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).
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
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.
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.
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.
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.