mirror of
https://github.com/teloxide/teloxide.git
synced 2025-01-03 17:52:12 +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)
|
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 {
|
pub(crate) fn description_is_enabled(&self) -> bool {
|
||||||
// FIXME: remove the first, `== "off"`, check eventually
|
// 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> {
|
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]
|
#[test]
|
||||||
#[cfg(feature = "macros")]
|
#[cfg(feature = "macros")]
|
||||||
fn descriptions_off() {
|
fn descriptions_off() {
|
||||||
|
// FIXME: Remove `off` doc comment when `off` removed.
|
||||||
#[derive(BotCommands, Debug, PartialEq)]
|
#[derive(BotCommands, Debug, PartialEq)]
|
||||||
#[command(rename_rule = "lowercase")]
|
#[command(rename_rule = "lowercase")]
|
||||||
enum DefaultCommands {
|
enum DefaultCommands {
|
||||||
|
@ -236,10 +237,11 @@ fn descriptions_off() {
|
||||||
Start,
|
Start,
|
||||||
#[command(hide)]
|
#[command(hide)]
|
||||||
Username,
|
Username,
|
||||||
|
/// off
|
||||||
Help,
|
Help,
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_eq!(DefaultCommands::descriptions().to_string(), "/help".to_owned());
|
assert_eq!(DefaultCommands::descriptions().to_string(), "/help — off".to_owned());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Reference in a new issue