Show the command in the help message, even if its description is off if it is written in doc comment

This commit is contained in:
TheAwiteb 2023-09-12 18:22:51 +03:00
parent 7e6198925f
commit 9eececeab2
No known key found for this signature in database
GPG key ID: ABF818BD15DC2D34
2 changed files with 12 additions and 3 deletions

View file

@ -65,12 +65,19 @@ impl Command {
self.description.as_ref().map(|(d, ..)| &**d)
}
pub fn contains_doc_comment(&self) -> bool {
self.description.as_ref().map(|(_, is_doc, ..)| *is_doc).unwrap_or(false)
}
pub(crate) fn description_is_enabled(&self) -> bool {
// FIXME: remove the first, `== "off"`, check eventually
self.description() != Some("off") && !self.hidden
!((self.description() == Some("off") && !self.contains_doc_comment()) || self.hidden)
}
pub(crate) fn deprecated_description_off_span(&self) -> Option<Span> {
self.description.as_ref().filter(|(d, ..)| d == "off").map(|&(.., span)| span)
self.description
.as_ref()
.filter(|(d, ..)| d == "off" && !self.description_is_enabled())
.map(|&(.., span)| span)
}
}

View file

@ -229,6 +229,7 @@ fn parse_named_fields() {
#[test]
#[cfg(feature = "macros")]
fn descriptions_off() {
// FIXME: Remove `off` doc comment when `off` removed.
#[derive(BotCommands, Debug, PartialEq)]
#[command(rename_rule = "lowercase")]
enum DefaultCommands {
@ -236,10 +237,11 @@ fn descriptions_off() {
Start,
#[command(hide)]
Username,
/// off
Help,
}
assert_eq!(DefaultCommands::descriptions().to_string(), "/help".to_owned());
assert_eq!(DefaultCommands::descriptions().to_string(), "/help — off".to_owned());
}
#[test]