mirror of
https://github.com/Start9Labs/rpc-toolkit.git
synced 2026-03-26 02:11:56 +00:00
fix rename
This commit is contained in:
@@ -74,6 +74,7 @@ pub struct ArgOptions {
|
||||
check_is_present: bool,
|
||||
help: Option<LitStr>,
|
||||
name: Option<Ident>,
|
||||
rename: Option<Ident>,
|
||||
short: Option<LitStr>,
|
||||
long: Option<LitStr>,
|
||||
parse: Option<Path>,
|
||||
|
||||
@@ -352,6 +352,7 @@ pub fn parse_arg_attr(attr: Attribute, arg: PatType) -> Result<ArgOptions> {
|
||||
Pat::Ident(i) => Some(i.ident),
|
||||
_ => None,
|
||||
},
|
||||
rename: None,
|
||||
short: None,
|
||||
long: None,
|
||||
parse: None,
|
||||
@@ -512,13 +513,13 @@ pub fn parse_arg_attr(attr: Attribute, arg: PatType) -> Result<ArgOptions> {
|
||||
}
|
||||
NestedMeta::Meta(Meta::NameValue(nv)) if nv.path.is_ident("rename") => {
|
||||
if let Lit::Str(rename) = nv.lit {
|
||||
if opt.name.is_some() {
|
||||
if opt.rename.is_some() {
|
||||
return Err(Error::new(
|
||||
rename.span(),
|
||||
"duplicate argument `rename`",
|
||||
));
|
||||
}
|
||||
opt.name = Some(
|
||||
opt.rename = Some(
|
||||
syn::parse_str(&rename.value())
|
||||
.map_err(|e| Error::new(rename.span(), format!("{}", e)))?,
|
||||
);
|
||||
@@ -600,6 +601,7 @@ pub fn parse_arg_attr(attr: Attribute, arg: PatType) -> Result<ArgOptions> {
|
||||
Meta::Path(_) => (),
|
||||
Meta::NameValue(nv) => return Err(Error::new(nv.span(), "`arg` cannot be assigned to")),
|
||||
}
|
||||
opt.name = opt.name.or(opt.rename.clone());
|
||||
if opt.name.is_none() {
|
||||
return Err(Error::new(
|
||||
arg_span,
|
||||
|
||||
Reference in New Issue
Block a user