mirror of
https://github.com/teloxide/teloxide.git
synced 2025-01-03 09:49:07 +01:00
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:
parent
7e6198925f
commit
9eececeab2
2 changed files with 12 additions and 3 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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]
|
||||
|
|
Loading…
Reference in a new issue