mirror of
https://github.com/Start9Labs/rpc-toolkit.git
synced 2026-03-30 12:21:58 +00:00
create rpc toolkit
This commit is contained in:
85
rpc-toolkit-macro-internals/src/command/mod.rs
Normal file
85
rpc-toolkit-macro-internals/src/command/mod.rs
Normal file
@@ -0,0 +1,85 @@
|
||||
use syn::*;
|
||||
|
||||
pub mod build;
|
||||
mod parse;
|
||||
|
||||
pub enum ExecutionContext {
|
||||
Standard,
|
||||
LocalOnly(Path),
|
||||
RemoteOnly(Path),
|
||||
}
|
||||
impl Default for ExecutionContext {
|
||||
fn default() -> Self {
|
||||
ExecutionContext::Standard
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct LeafOptions {
|
||||
blocking: Option<Path>,
|
||||
is_async: bool,
|
||||
about: Option<LitStr>,
|
||||
rename: Option<Ident>,
|
||||
exec_ctx: ExecutionContext,
|
||||
display: Option<Path>,
|
||||
}
|
||||
|
||||
pub struct SelfImplInfo {
|
||||
path: Path,
|
||||
is_async: bool,
|
||||
blocking: bool,
|
||||
}
|
||||
pub struct ParentOptions {
|
||||
common: LeafOptions,
|
||||
subcommands: Vec<Path>,
|
||||
self_impl: Option<SelfImplInfo>,
|
||||
}
|
||||
impl From<LeafOptions> for ParentOptions {
|
||||
fn from(opt: LeafOptions) -> Self {
|
||||
ParentOptions {
|
||||
common: opt,
|
||||
subcommands: Default::default(),
|
||||
self_impl: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub enum Options {
|
||||
Leaf(LeafOptions),
|
||||
Parent(ParentOptions),
|
||||
}
|
||||
impl Options {
|
||||
fn to_parent(&mut self) -> Result<&mut ParentOptions> {
|
||||
if let Options::Leaf(opt) = self {
|
||||
*self = Options::Parent(std::mem::replace(opt, Default::default()).into());
|
||||
}
|
||||
Ok(match self {
|
||||
Options::Parent(a) => a,
|
||||
_ => unreachable!(),
|
||||
})
|
||||
}
|
||||
fn common(&mut self) -> &mut LeafOptions {
|
||||
match self {
|
||||
Options::Leaf(ref mut opt) => opt,
|
||||
Options::Parent(opt) => &mut opt.common,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ArgOptions {
|
||||
ty: Type,
|
||||
optional: bool,
|
||||
check_is_present: bool,
|
||||
help: Option<LitStr>,
|
||||
name: Option<Ident>,
|
||||
short: Option<LitStr>,
|
||||
long: Option<LitStr>,
|
||||
parse: Option<Path>,
|
||||
stdin: bool,
|
||||
}
|
||||
|
||||
pub enum ParamType {
|
||||
None,
|
||||
Arg(ArgOptions),
|
||||
Context(Type),
|
||||
}
|
||||
Reference in New Issue
Block a user