I like Docopt for quick scripts, used it both in Python and Rust projects. It is quite unflexible though.
The Rust Docopt implementation¹ was deprecated this year, which is probably good because clap v3² is so awesome. In a project of mine (tealdeer), I noticed that docopt.rs was responsible for the huge majority of CPU instructions when running the binary: https://github.com/dbrgn/tealdeer/issues/106#issuecomment-59... I then switched³ to clap and shaved off almost a megabyte from the release binary⁴. Performance improved as well, time required for rendering a tldr page went down from ~15.9 ms to ~12.4 ms⁵. With the migration, we also managed to reduce a lot of custom validation logic and move this logic into the derive macro attributes.
I agree that clap v3 (with it's derive capabilities basically incorporating structopt) is awesome. But it's still pretty heavyweight, although you can make it a bit more lightweight by turning off some features. In some cases, I actually put the CLI args in a separate crate, so that changing the program doesn't involve rebuilding the CLI arg structures. As a bonus, it makes changes to the CLI much more obvious in code review.
Ah, I've been using the betas and release candidates for a while now. Amazing it's finally stable, thank you.
Also, I don't necessarily blame clap for being heavyweight. Argument parsing is hard, and clap does it well - with nice help output!
I've also accepted the cost of proc macros (at least while syn is not in the standard library). For me, the derived style where I get populated structures out is well worth it.
Of course, any improvement is welcome. But clap works great for me, and is a dependency I happily pull in.
> Also, I don't necessarily blame clap for being heavyweight. Argument parsing is hard, and clap does it well - with nice help output!
While the feature set justifies some of the cost, I don't want to be complacent about it and excuse any excess as just coming from the feature set. I think we have a lot of room for improvement.
Hmm, putting them in a subcrate / separate compilation unit is pretty smart. I can imagine that quite a chunk of the compilation time goes into the proc macros :)
The Rust Docopt implementation¹ was deprecated this year, which is probably good because clap v3² is so awesome. In a project of mine (tealdeer), I noticed that docopt.rs was responsible for the huge majority of CPU instructions when running the binary: https://github.com/dbrgn/tealdeer/issues/106#issuecomment-59... I then switched³ to clap and shaved off almost a megabyte from the release binary⁴. Performance improved as well, time required for rendering a tldr page went down from ~15.9 ms to ~12.4 ms⁵. With the migration, we also managed to reduce a lot of custom validation logic and move this logic into the derive macro attributes.
¹ https://github.com/docopt/docopt.rs
² https://github.com/clap-rs/clap
³ https://github.com/dbrgn/tealdeer/pull/108
⁴ https://github.com/dbrgn/tealdeer/pull/108#issuecomment-9448...
⁵ https://github.com/dbrgn/tealdeer/pull/108#issuecomment-9448...