Allow doc comment to set help text#14
Conversation
This treats doc comments as `help`/`about` attributes, which may lead to concatenating the original help text with the doc comment.
| #[derive(Debug, Clone, Copy)] | ||
| enum AttrSource { Struct, Field, } | ||
|
|
||
| fn extract_attrs<'a>(attrs: &'a [Attribute], attr_source: AttrSource) -> Box<Iterator<Item = (Ident, Lit)> + 'a> { |
There was a problem hiding this comment.
I was pretty close to making this a Box<Iterator<Item = (Cow<'a, Ident>, Cow<'a, Lit>)> but luckily I noticed early enough that this was derive macro whose performance will probably never matter 😅
|
Great work, thanks! I'd prefer that if help is provided, help is used, else the docstring is used. But it looks like the last seen will be used, thus better to revert the chain. To be sure of the result, can you add an example in Thanks. |
This changes the behavior of `from_attr_or_env` (used for clap application settings) to favor the last occurrence of the requested attribute. This is what repeatedly calling the same methods to set field properties does implicitly.
|
Alright, help/about is now preferred if the doc string is also set, and I added some tests comparing the help output that clap's |
| } | ||
|
|
||
| fn from_attr_or_env(attrs: &[(&Ident, &Lit)], key: &str, env: &str) -> Lit { | ||
| fn from_attr_or_env<'a>(attrs: &[(Ident, Lit)], key: &str, env: &str) -> Lit { |
|
Thanks! I'll update crates.io after eating. |
|
Thanks! Bon appétit! |
|
Published |
|
I think you just published a new version of structopt but not structopt-derive? |
|
oups, should be fixed |
Narrow API surface
This treats doc comments as
help/aboutattributes, which may lead to concatenating the original help text with the doc comment.I didn't add any tests except for changing the 'basic' example and checking the CLI output myself. If there is anything you want me to add in that regard, let me know :)
fix #13