I’m about to finish the book and have decided to start creating various small CLI applications. I’m currently working on a to-do app: GitHub - kaanboraoz/tutorial-projects.
I’m a bit unsure about how to handle CLI arguments. I’ve looked into clap, but I couldn’t find very clear documentation. Any suggestions or guidance would be greatly appreciated!
The clap crate is the way to go for non trivial command line parsing. It needs some effort to learn. Documentation is
Or, when you think that you need a very gentle introduction, you might buy the book "Command line Rust" -- but ensure that you get the updated version for the current clap version. I think you might be able to read a few pages of the book at Google docs. The book is quite well written, but the progress is very slow.
I believe that the library requires to define your arguments as some struct. If you are more comfortable with ad hoc solution, then take a look at the command arguments processor. I didn't finish the library yet, so I am interested in any feedback especially from people not having any experience with reputable argument processors as clap.
Clap is complicated as it needs to be, but only complicated if you have a complicated CLI. It makes complicated CLI, easier than doing it manually. If you have simple CLI needs, the clapping can can be learned or taught to you, simply. If you have complicated needs, maybe start out simple, until you figure out how to clap, then it gets easy to make it complicated later.
Even if you only have a flag or two, using clap is nice because you get --help, --version, for FREE!
In your "to-do" app what are the command line options you want to have?