mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 14:35:36 +01:00
Rename rename
=> rename_rule
This commit is contained in:
parent
53d7548815
commit
26eba3eb14
2 changed files with 29 additions and 23 deletions
|
@ -27,7 +27,7 @@ pub(crate) struct CommandAttr {
|
|||
pub(crate) enum CommandAttrKind {
|
||||
Prefix(String),
|
||||
Description(String),
|
||||
Rename(RenameRule),
|
||||
RenameRule(RenameRule),
|
||||
ParseWith(ParserType),
|
||||
Separator(String),
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ impl CommandAttrs {
|
|||
match attr.kind {
|
||||
Prefix(p) => insert(&mut this.prefix, p, attr.sp),
|
||||
Description(d) => insert(&mut this.description, d, attr.sp),
|
||||
Rename(r) => insert(&mut this.rename_rule, r, attr.sp),
|
||||
RenameRule(r) => insert(&mut this.rename_rule, r, attr.sp),
|
||||
ParseWith(p) => insert(&mut this.parser, p, attr.sp),
|
||||
Separator(s) => insert(&mut this.separator, s, attr.sp),
|
||||
}?;
|
||||
|
@ -87,8 +87,10 @@ impl CommandAttr {
|
|||
let kind = match &*key.to_string() {
|
||||
"prefix" => Prefix(value.expect_string()?),
|
||||
"description" => Description(value.expect_string()?),
|
||||
"rename" => Rename(
|
||||
value.expect_string().and_then(|r| RenameRule::parse(&r))?,
|
||||
"rename_rule" => RenameRule(
|
||||
value
|
||||
.expect_string()
|
||||
.and_then(|r| self::RenameRule::parse(&r))?,
|
||||
),
|
||||
"parse_with" => {
|
||||
ParseWith(value.expect_string().map(|p| ParserType::parse(&p))?)
|
||||
|
|
|
@ -9,7 +9,7 @@ use teloxide::utils::command::BotCommands as _;
|
|||
#[test]
|
||||
fn parse_command_with_args() {
|
||||
#[derive(BotCommands, Debug, PartialEq)]
|
||||
#[command(rename = "lowercase")]
|
||||
#[command(rename_rule = "lowercase")]
|
||||
enum DefaultCommands {
|
||||
Start(String),
|
||||
Help,
|
||||
|
@ -24,7 +24,7 @@ fn parse_command_with_args() {
|
|||
#[test]
|
||||
fn parse_command_with_non_string_arg() {
|
||||
#[derive(BotCommands, Debug, PartialEq)]
|
||||
#[command(rename = "lowercase")]
|
||||
#[command(rename_rule = "lowercase")]
|
||||
enum DefaultCommands {
|
||||
Start(i32),
|
||||
Help,
|
||||
|
@ -39,7 +39,7 @@ fn parse_command_with_non_string_arg() {
|
|||
#[test]
|
||||
fn attribute_prefix() {
|
||||
#[derive(BotCommands, Debug, PartialEq)]
|
||||
#[command(rename = "lowercase")]
|
||||
#[command(rename_rule = "lowercase")]
|
||||
enum DefaultCommands {
|
||||
#[command(prefix = "!")]
|
||||
Start(String),
|
||||
|
@ -55,7 +55,7 @@ fn attribute_prefix() {
|
|||
#[test]
|
||||
fn many_attributes() {
|
||||
#[derive(BotCommands, Debug, PartialEq)]
|
||||
#[command(rename = "lowercase")]
|
||||
#[command(rename_rule = "lowercase")]
|
||||
enum DefaultCommands {
|
||||
#[command(prefix = "!", description = "desc")]
|
||||
Start,
|
||||
|
@ -75,7 +75,11 @@ fn many_attributes() {
|
|||
#[test]
|
||||
fn global_attributes() {
|
||||
#[derive(BotCommands, Debug, PartialEq)]
|
||||
#[command(prefix = "!", rename = "lowercase", description = "Bot commands")]
|
||||
#[command(
|
||||
prefix = "!",
|
||||
rename_rule = "lowercase",
|
||||
description = "Bot commands"
|
||||
)]
|
||||
enum DefaultCommands {
|
||||
#[command(prefix = "/")]
|
||||
Start,
|
||||
|
@ -99,7 +103,7 @@ fn global_attributes() {
|
|||
#[test]
|
||||
fn parse_command_with_bot_name() {
|
||||
#[derive(BotCommands, Debug, PartialEq)]
|
||||
#[command(rename = "lowercase")]
|
||||
#[command(rename_rule = "lowercase")]
|
||||
enum DefaultCommands {
|
||||
#[command(prefix = "/")]
|
||||
Start,
|
||||
|
@ -115,7 +119,7 @@ fn parse_command_with_bot_name() {
|
|||
#[test]
|
||||
fn parse_with_split() {
|
||||
#[derive(BotCommands, Debug, PartialEq)]
|
||||
#[command(rename = "lowercase")]
|
||||
#[command(rename_rule = "lowercase")]
|
||||
#[command(parse_with = "split")]
|
||||
enum DefaultCommands {
|
||||
Start(u8, String),
|
||||
|
@ -131,7 +135,7 @@ fn parse_with_split() {
|
|||
#[test]
|
||||
fn parse_with_split2() {
|
||||
#[derive(BotCommands, Debug, PartialEq)]
|
||||
#[command(rename = "lowercase")]
|
||||
#[command(rename_rule = "lowercase")]
|
||||
#[command(parse_with = "split", separator = "|")]
|
||||
enum DefaultCommands {
|
||||
Start(u8, String),
|
||||
|
@ -174,7 +178,7 @@ fn parse_custom_parser() {
|
|||
use parser::custom_parse_function;
|
||||
|
||||
#[derive(BotCommands, Debug, PartialEq)]
|
||||
#[command(rename = "lowercase")]
|
||||
#[command(rename_rule = "lowercase")]
|
||||
enum DefaultCommands {
|
||||
#[command(parse_with = "custom_parse_function")]
|
||||
Start(u8, String),
|
||||
|
@ -199,7 +203,7 @@ fn parse_custom_parser() {
|
|||
#[test]
|
||||
fn parse_named_fields() {
|
||||
#[derive(BotCommands, Debug, PartialEq)]
|
||||
#[command(rename = "lowercase")]
|
||||
#[command(rename_rule = "lowercase")]
|
||||
#[command(parse_with = "split")]
|
||||
enum DefaultCommands {
|
||||
Start { num: u8, data: String },
|
||||
|
@ -215,7 +219,7 @@ fn parse_named_fields() {
|
|||
#[test]
|
||||
fn descriptions_off() {
|
||||
#[derive(BotCommands, Debug, PartialEq)]
|
||||
#[command(rename = "lowercase")]
|
||||
#[command(rename_rule = "lowercase")]
|
||||
enum DefaultCommands {
|
||||
#[command(description = "off")]
|
||||
Start,
|
||||
|
@ -229,21 +233,21 @@ fn descriptions_off() {
|
|||
fn rename_rules() {
|
||||
#[derive(BotCommands, Debug, PartialEq)]
|
||||
enum DefaultCommands {
|
||||
#[command(rename = "lowercase")]
|
||||
#[command(rename_rule = "lowercase")]
|
||||
AaaAaa,
|
||||
#[command(rename = "UPPERCASE")]
|
||||
#[command(rename_rule = "UPPERCASE")]
|
||||
BbbBbb,
|
||||
#[command(rename = "PascalCase")]
|
||||
#[command(rename_rule = "PascalCase")]
|
||||
CccCcc,
|
||||
#[command(rename = "camelCase")]
|
||||
#[command(rename_rule = "camelCase")]
|
||||
DddDdd,
|
||||
#[command(rename = "snake_case")]
|
||||
#[command(rename_rule = "snake_case")]
|
||||
EeeEee,
|
||||
#[command(rename = "SCREAMING_SNAKE_CASE")]
|
||||
#[command(rename_rule = "SCREAMING_SNAKE_CASE")]
|
||||
FffFff,
|
||||
#[command(rename = "kebab-case")]
|
||||
#[command(rename_rule = "kebab-case")]
|
||||
GggGgg,
|
||||
#[command(rename = "SCREAMING-KEBAB-CASE")]
|
||||
#[command(rename_rule = "SCREAMING-KEBAB-CASE")]
|
||||
HhhHhh,
|
||||
//#[command(rename = "Bar")]
|
||||
//Foo,
|
||||
|
|
Loading…
Reference in a new issue