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