Replies: 6 comments 17 replies
-
Tutorial First of all, doing a text search for "raw" on the rendered tutorial doesn't yield any results. Looking through it quickly, maybe the tutorial could use a section on how clap uses attributes? They're mentioned in a few places they get a short mention, but nothing dedicated to them. Reference Also, people have a tendency to skip around, especially if a document is titled "Reference". Many readers will probably skip a section called "Terminology", and only go back to it if they don't understand a term. As it currently only describes magic vs raw attributes, I'd change the title (maybe something like "Attribute types"?), and possibly add a "Terminology" section in the future if it is necessary. |
Beta Was this translation helpful? Give feedback.
-
So what happened to me was my goal was 'to hide an attribute'. So first step was to look at https://docs.rs/clap/latest/clap/_derive/index.html and to cmd-f for "hid" to match hide or hidden. When nothing matched, I looked manually at https://docs.rs/clap/latest/clap/_derive/index.html#command-attributes and didn't see anything there. At that point I wondered "is hiding even supported?" so I searched it in the api docs https://docs.rs/clap/latest/clap/?search=hid here, which led me to https://docs.rs/clap/latest/clap/builder/struct.Command.html#method.hide So at this point I knew hiding was possible, but I couldn't connect how to connect that with derive. It turned out the answer was "https://docs.rs/clap/latest/clap/_derive/index.html#terminology" but I didn't see that because it was above the Command attribute section! There is a similar comment in Command attributes but because I saw that before I searched for the method and I was focused on the goal, I didn't connect that I could use the method as an attribute here. So I'm not 100% sure on how to "improve" this. I think generally as a developer when we are looking for something we already know, we don't read top to bottom, but try to narrow down to a specific point for that implementation detail, which in this case meant that I missed the information that connected these concepts. Even maybe something as silly as a list of the methods that can be used as attributes in the raw attributes section would help because then people can see the connection? It doesn't need full examples or explanations, but it would help people to "see" that it's possible. Alternately, the reverse, where "https://docs.rs/clap/latest/clap/builder/struct.Command.html#method.hide" shows an example of it use as an attribute? |
Beta Was this translation helpful? Give feedback.
-
I was going to leave an issue about the lack of documentation of Derive API attributes. Thankfully the issue template directed me here! Anyway, I agree that derive attributes are very hard to find. I looked in the tutorial and found a bunch of disparate examples of how to use attributes, but these only covered the common cases and didn't really provide a jumping-off point to help me go beyond, or learn how to go beyond, what was covered there. (In this regard it's a bit more more like a cookbook than a tutorial.) (I just now realized that the tutorial does say “You can use attributes to change the application level behavior of clap. Any Command builder function can be used as an attribute.”, but it's pretty discreet, sandwiched between two code blocks.) Then, in the reference, I stumbled upon the magic sentence:
This was when the lightbulb went off: if you don't know how to do something with the derive API, but you know it doesn't involve a magic attribute, then the way to find out how to accomplish your goal is to search for a reasonably-named method in the builder API and just use that method as an attribute. I think that this concept should be plastered everywhere in clap’s derive API documentation and you should never have to scroll too far to see it. One way to achieve this, which I think would also be helpful more generally, would be to have a “Concepts” section in the tutorial, probably above the “Quick Start” section, which lays out the basic concepts of the derive API:
If there's consensus on this I'd be happy to submit a small docs PR. |
Beta Was this translation helpful? Give feedback.
-
While its not a definitive fix, I'm hoping that #4985 is an incremental improvement |
Beta Was this translation helpful? Give feedback.
-
Kind of an out-there idea is we could create a cargo xtask to use rustdoc json output (nightly only) to extract all of the builder methods that may be used as an attribute and inject that into the reference, linking to the builder methods. This would improve discoverability but wouldn't help with providing derive-specific examples. We'd also have to deal with the overlap between magic attributes that also have a builder method. |
Beta Was this translation helpful? Give feedback.
-
Frankly, I don't think this approach is a good idea. I came here via #1751 and feeling very frustrated by the responses in that thread. I eventually found the answer to the question I was asking via Stack Overflow or similar. To me that suggests there is a usability issue here and to read that you are intentionally not providing the missing documentation is … not encouraging. I hope that you will find it in your hearts to reconsider this approach. |
Beta Was this translation helpful? Give feedback.
-
Probably the most frequent support issue with the derive API is so called "raw attributes" which forward directly to the builder API.
For example:
#[clap(global)]
example & docs #4087Our stance has been that we have intentionally decided to not enumerate every possible attribute in the derive documentation due to the maintenance burden of that. Instead the derive reference explains how raw attributes work and reminds people when looking at Command attributes that raw attributes exist, linking to the relevant documentation for using those raw attributes.
How can we improve discoverability, reduce confusion, and ideally keep maintenance costs down?
Beta Was this translation helpful? Give feedback.
All reactions