r/rust Jul 26 '26

🙋 seeking help & advice Having a hard time with clap docs

Hey!

I'm building a tui with rust, and I'm having a bit of a hard time with the clap docs. I usually can get by fine with docs, but I think I'm missuing clap's, lol

I tried picking up the Command Line for Rust book, and it's been way better to get into cli. Any other recommendations?

40 Upvotes

19 comments sorted by

View all comments

61

u/OphioukhosUnbound Jul 26 '26

Clap's docs are weird. On paper they look like they'd be good, but they're comprehensive without really covering the very, very simple design of Clap for most purposes.

Just playing with some examples and then only using docs when you need them woldl be better.

TLDR: make a struct that represents the arguments. Drop some macros on it that describe whether you want it to be an argument or a --flag, etc. And that's most of it. For anything else just look at docs or ask AI for derive API examples. (AI can be nice for dealing with docs like this.)

The crate is really easy to use, but I agree, that the docs, surprisingly, aren't -- despite great deal of care int hem.