mirror of
https://github.com/Start9Labs/rpc-toolkit.git
synced 2026-03-30 20:24:48 +00:00
local -> cli_only;remote -> rpc_only;both -> local
This commit is contained in:
@@ -264,7 +264,7 @@ fn rpc_handler(
|
||||
_ => unreachable!(),
|
||||
});
|
||||
match opt {
|
||||
Options::Leaf(opt) if matches!(opt.exec_ctx, ExecutionContext::LocalOnly(_)) => quote! {
|
||||
Options::Leaf(opt) if matches!(opt.exec_ctx, ExecutionContext::CliOnly(_)) => quote! {
|
||||
#param_struct_def
|
||||
|
||||
pub async fn rpc_handler#fn_generics(
|
||||
@@ -347,7 +347,7 @@ fn rpc_handler(
|
||||
}
|
||||
};
|
||||
match self_impl {
|
||||
Some(self_impl) if !matches!(common.exec_ctx, ExecutionContext::LocalOnly(_)) => {
|
||||
Some(self_impl) if !matches!(common.exec_ctx, ExecutionContext::CliOnly(_)) => {
|
||||
let self_impl_fn = &self_impl.path;
|
||||
let self_impl = if self_impl.is_async {
|
||||
quote_spanned! { self_impl_fn.span() =>
|
||||
@@ -552,7 +552,7 @@ fn cli_handler(
|
||||
quote! { rpc_toolkit_prelude::default_display }
|
||||
};
|
||||
match opt {
|
||||
Options::Leaf(opt) if matches!(opt.exec_ctx, ExecutionContext::RemoteOnly(_)) => quote! {
|
||||
Options::Leaf(opt) if matches!(opt.exec_ctx, ExecutionContext::RpcOnly(_)) => quote! {
|
||||
pub fn cli_handler#generics(
|
||||
_ctx: #ctx_ty,
|
||||
_rt: Option<rpc_toolkit_prelude::Runtime>,
|
||||
@@ -566,7 +566,7 @@ fn cli_handler(
|
||||
})
|
||||
}
|
||||
},
|
||||
Options::Leaf(opt) if matches!(opt.exec_ctx, ExecutionContext::LocalOnly(_)) => {
|
||||
Options::Leaf(opt) if matches!(opt.exec_ctx, ExecutionContext::CliOnly(_)) => {
|
||||
let invocation = if opt.is_async {
|
||||
quote! {
|
||||
rt_ref.block_on(#fn_path(#(#param),*))?
|
||||
@@ -687,7 +687,7 @@ fn cli_handler(
|
||||
}
|
||||
});
|
||||
let self_impl = match (self_impl, &common.exec_ctx) {
|
||||
(Some(self_impl), ExecutionContext::LocalOnly(_)) => {
|
||||
(Some(self_impl), ExecutionContext::CliOnly(_)) => {
|
||||
let self_impl_fn = &self_impl.path;
|
||||
let create_rt = if common.is_async {
|
||||
None
|
||||
|
||||
@@ -5,8 +5,9 @@ mod parse;
|
||||
|
||||
pub enum ExecutionContext {
|
||||
Standard,
|
||||
LocalOnly(Path),
|
||||
RemoteOnly(Path),
|
||||
CliOnly(Path),
|
||||
RpcOnly(Path),
|
||||
Local(Path),
|
||||
}
|
||||
impl Default for ExecutionContext {
|
||||
fn default() -> Self {
|
||||
|
||||
@@ -126,18 +126,92 @@ pub fn parse_command_attr(args: AttributeArgs) -> Result<Options> {
|
||||
"`display` cannot be assigned to",
|
||||
));
|
||||
}
|
||||
NestedMeta::Meta(Meta::Path(p)) if p.is_ident("cli_only") => {
|
||||
match &opt.common().exec_ctx {
|
||||
ExecutionContext::Standard => {
|
||||
opt.common().exec_ctx = ExecutionContext::CliOnly(p)
|
||||
}
|
||||
ExecutionContext::CliOnly(_) => {
|
||||
return Err(Error::new(p.span(), "duplicate argument: `cli_only`"))
|
||||
}
|
||||
ExecutionContext::RpcOnly(_) => {
|
||||
return Err(Error::new(
|
||||
p.span(),
|
||||
"`cli_only` and `rpc_only` are mutually exclusive",
|
||||
))
|
||||
}
|
||||
ExecutionContext::Local(_) => {
|
||||
return Err(Error::new(
|
||||
p.span(),
|
||||
"`cli_only` and `local` are mutually exclusive",
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
NestedMeta::Meta(Meta::List(list)) if list.path.is_ident("cli_only") => {
|
||||
return Err(Error::new(
|
||||
list.path.span(),
|
||||
"`cli_only` does not take any arguments",
|
||||
));
|
||||
}
|
||||
NestedMeta::Meta(Meta::NameValue(nv)) if nv.path.is_ident("cli_only") => {
|
||||
return Err(Error::new(
|
||||
nv.path.span(),
|
||||
"`cli_only` cannot be assigned to",
|
||||
));
|
||||
}
|
||||
NestedMeta::Meta(Meta::Path(p)) if p.is_ident("rpc_only") => {
|
||||
match &opt.common().exec_ctx {
|
||||
ExecutionContext::Standard => {
|
||||
opt.common().exec_ctx = ExecutionContext::RpcOnly(p)
|
||||
}
|
||||
ExecutionContext::RpcOnly(_) => {
|
||||
return Err(Error::new(p.span(), "duplicate argument: `rpc_only`"))
|
||||
}
|
||||
ExecutionContext::CliOnly(_) => {
|
||||
return Err(Error::new(
|
||||
p.span(),
|
||||
"`rpc_only` and `cli_only` are mutually exclusive",
|
||||
))
|
||||
}
|
||||
ExecutionContext::Local(_) => {
|
||||
return Err(Error::new(
|
||||
p.span(),
|
||||
"`rpc_only` and `local` are mutually exclusive",
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
NestedMeta::Meta(Meta::List(list)) if list.path.is_ident("rpc_only") => {
|
||||
return Err(Error::new(
|
||||
list.path.span(),
|
||||
"`rpc_only` does not take any arguments",
|
||||
));
|
||||
}
|
||||
NestedMeta::Meta(Meta::NameValue(nv)) if nv.path.is_ident("rpc_only") => {
|
||||
return Err(Error::new(
|
||||
nv.path.span(),
|
||||
"`rpc_only` cannot be assigned to",
|
||||
));
|
||||
}
|
||||
NestedMeta::Meta(Meta::Path(p)) if p.is_ident("local") => {
|
||||
match &opt.common().exec_ctx {
|
||||
ExecutionContext::Standard => {
|
||||
opt.common().exec_ctx = ExecutionContext::LocalOnly(p)
|
||||
opt.common().exec_ctx = ExecutionContext::Local(p)
|
||||
}
|
||||
ExecutionContext::LocalOnly(_) => {
|
||||
ExecutionContext::Local(_) => {
|
||||
return Err(Error::new(p.span(), "duplicate argument: `local`"))
|
||||
}
|
||||
ExecutionContext::RemoteOnly(_) => {
|
||||
ExecutionContext::RpcOnly(_) => {
|
||||
return Err(Error::new(
|
||||
p.span(),
|
||||
"`local` and `remote` are mutually exclusive",
|
||||
"`local` and `rpc_only` are mutually exclusive",
|
||||
))
|
||||
}
|
||||
ExecutionContext::CliOnly(_) => {
|
||||
return Err(Error::new(
|
||||
p.span(),
|
||||
"`local` and `cli_only` are mutually exclusive",
|
||||
))
|
||||
}
|
||||
}
|
||||
@@ -151,31 +225,6 @@ pub fn parse_command_attr(args: AttributeArgs) -> Result<Options> {
|
||||
NestedMeta::Meta(Meta::NameValue(nv)) if nv.path.is_ident("local") => {
|
||||
return Err(Error::new(nv.path.span(), "`local` cannot be assigned to"));
|
||||
}
|
||||
NestedMeta::Meta(Meta::Path(p)) if p.is_ident("remote") => {
|
||||
match &opt.common().exec_ctx {
|
||||
ExecutionContext::Standard => {
|
||||
opt.common().exec_ctx = ExecutionContext::RemoteOnly(p)
|
||||
}
|
||||
ExecutionContext::LocalOnly(_) => {
|
||||
return Err(Error::new(p.span(), "duplicate argument: `remote`"))
|
||||
}
|
||||
ExecutionContext::RemoteOnly(_) => {
|
||||
return Err(Error::new(
|
||||
p.span(),
|
||||
"`local` and `remote` are mutually exclusive",
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
NestedMeta::Meta(Meta::List(list)) if list.path.is_ident("remote") => {
|
||||
return Err(Error::new(
|
||||
list.path.span(),
|
||||
"`remote` does not take any arguments",
|
||||
));
|
||||
}
|
||||
NestedMeta::Meta(Meta::NameValue(nv)) if nv.path.is_ident("remote") => {
|
||||
return Err(Error::new(nv.path.span(), "`remote` cannot be assigned to"));
|
||||
}
|
||||
NestedMeta::Meta(Meta::Path(p)) if p.is_ident("blocking") => {
|
||||
if opt.common().blocking.is_some() {
|
||||
return Err(Error::new(p.span(), "duplicate argument `blocking`"));
|
||||
@@ -249,16 +298,16 @@ pub fn parse_command_attr(args: AttributeArgs) -> Result<Options> {
|
||||
));
|
||||
}
|
||||
match &opt.common.exec_ctx {
|
||||
ExecutionContext::LocalOnly(local) => {
|
||||
ExecutionContext::CliOnly(cli_only) => {
|
||||
return Err(Error::new(
|
||||
local.span(),
|
||||
"cannot define `local` for a command without an implementation",
|
||||
cli_only.span(),
|
||||
"cannot define `cli_only` for a command without an implementation",
|
||||
))
|
||||
}
|
||||
ExecutionContext::RemoteOnly(remote) => {
|
||||
ExecutionContext::RpcOnly(rpc_only) => {
|
||||
return Err(Error::new(
|
||||
remote.span(),
|
||||
"cannot define `remote` for a command without an implementation",
|
||||
rpc_only.span(),
|
||||
"cannot define `rpc_only` for a command without an implementation",
|
||||
))
|
||||
}
|
||||
_ => (),
|
||||
|
||||
Reference in New Issue
Block a user