fixes and added type safe arguments

This commit is contained in:
p0lunin 2020-04-25 19:57:45 +03:00
parent 801ee3a9c9
commit 0ef5a59a1a
4 changed files with 16 additions and 8 deletions

View file

@ -40,7 +40,12 @@ impl Command {
} else {
"/"
};
String::from(prefix) + &self.name
if let Some(rule) = &global_parameters.rename_rule {
String::from(prefix) + &rename_by_rule(&self.name, rule.as_str())
}
else {
String::from(prefix) + &self.name
}
}
}

View file

@ -1,5 +1,6 @@
use crate::attr::{Attr, BotCommandAttribute};
#[derive(Debug)]
pub struct CommandEnum {
pub prefix: Option<String>,
pub description: Option<String>,

View file

@ -1,11 +1,13 @@
extern crate quote;
use quote::quote;
use quote::{quote};
use syn::FieldsUnnamed;
pub fn impl_parse_args_unnamed(data: &FieldsUnnamed) -> quote::__rt::TokenStream {
let iter = 0..data.unnamed.len();
quote! {
(#(FromStr::from_str(args.get(#iter)),)*)
let mut tokens = quote! {};
for _ in iter {
tokens.extend(quote! { CommandArgument::parse(&mut args)?, });
}
quote! { (#tokens) }
}

View file

@ -103,8 +103,8 @@ fn impl_descriptions(infos: &[Command], global: &CommandEnum) -> quote::__rt::To
});
quote! {
fn descriptions() -> &'static str {
std::concat!(#global_description #(#command, #description, '\n'),*)
fn descriptions() -> String {
std::concat!(#global_description #(#command, #description, '\n'),*).to_string()
}
}
}
@ -123,7 +123,7 @@ fn impl_parse(
where
N: Into<String>
{
let mut words = s.split_whitespace();
let mut words = s.splitn(2, ' ');
let mut splited = words.next()?.split('@');
let command_raw = splited.next()?;
let bot = splited.next();
@ -133,7 +133,7 @@ fn impl_parse(
None => {}
_ => return None,
}
let args: Vec<&str> = words.collect();
let mut args = words.next().unwrap_or("").to_string();
match command_raw {
#(
#matching_values => Some(Self::#variant_ident #variants_initialization),