mirror of
https://github.com/Start9Labs/rpc-toolkit.git
synced 2026-03-26 02:11:56 +00:00
finish todos
This commit is contained in:
@@ -10,7 +10,6 @@ use serde::{Deserialize, Serialize};
|
|||||||
use yajrc::RpcError;
|
use yajrc::RpcError;
|
||||||
|
|
||||||
use crate::context::{AnyContext, IntoContext};
|
use crate::context::{AnyContext, IntoContext};
|
||||||
use crate::handler;
|
|
||||||
use crate::util::{combine, internal_error, invalid_params, Flat};
|
use crate::util::{combine, internal_error, invalid_params, Flat};
|
||||||
|
|
||||||
struct HandleAnyArgs {
|
struct HandleAnyArgs {
|
||||||
@@ -52,19 +51,21 @@ trait HandleAny {
|
|||||||
}
|
}
|
||||||
|
|
||||||
trait CliBindingsAny {
|
trait CliBindingsAny {
|
||||||
fn cli_command(&self) -> Command;
|
fn cli_command(&self, ctx_ty: TypeId) -> Command;
|
||||||
fn cli_parse(
|
fn cli_parse(
|
||||||
&self,
|
&self,
|
||||||
matches: &ArgMatches,
|
matches: &ArgMatches,
|
||||||
|
ctx_ty: TypeId,
|
||||||
) -> Result<(VecDeque<&'static str>, Value), clap::Error>;
|
) -> Result<(VecDeque<&'static str>, Value), clap::Error>;
|
||||||
fn cli_display(&self, handle_args: HandleAnyArgs, result: Value) -> Result<(), RpcError>;
|
fn cli_display(&self, handle_args: HandleAnyArgs, result: Value) -> Result<(), RpcError>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait CliBindings<Context: IntoContext>: Handler<Context> {
|
pub trait CliBindings<Context: IntoContext>: Handler<Context> {
|
||||||
fn cli_command(&self) -> Command;
|
fn cli_command(&self, ctx_ty: TypeId) -> Command;
|
||||||
fn cli_parse(
|
fn cli_parse(
|
||||||
&self,
|
&self,
|
||||||
matches: &ArgMatches,
|
matches: &ArgMatches,
|
||||||
|
ctx_ty: TypeId,
|
||||||
) -> Result<(VecDeque<&'static str>, Value), clap::Error>;
|
) -> Result<(VecDeque<&'static str>, Value), clap::Error>;
|
||||||
fn cli_display(
|
fn cli_display(
|
||||||
&self,
|
&self,
|
||||||
@@ -137,12 +138,13 @@ where
|
|||||||
H::Params: FromArgMatches + CommandFactory + Serialize,
|
H::Params: FromArgMatches + CommandFactory + Serialize,
|
||||||
H: PrintCliResult<Context>,
|
H: PrintCliResult<Context>,
|
||||||
{
|
{
|
||||||
fn cli_command(&self) -> Command {
|
fn cli_command(&self, _: TypeId) -> Command {
|
||||||
H::Params::command()
|
H::Params::command()
|
||||||
}
|
}
|
||||||
fn cli_parse(
|
fn cli_parse(
|
||||||
&self,
|
&self,
|
||||||
matches: &ArgMatches,
|
matches: &ArgMatches,
|
||||||
|
_: TypeId,
|
||||||
) -> Result<(VecDeque<&'static str>, Value), clap::Error> {
|
) -> Result<(VecDeque<&'static str>, Value), clap::Error> {
|
||||||
H::Params::from_arg_matches(matches).and_then(|a| {
|
H::Params::from_arg_matches(matches).and_then(|a| {
|
||||||
Ok((
|
Ok((
|
||||||
@@ -241,14 +243,15 @@ where
|
|||||||
H::Ok: Serialize + DeserializeOwned,
|
H::Ok: Serialize + DeserializeOwned,
|
||||||
RpcError: From<H::Err>,
|
RpcError: From<H::Err>,
|
||||||
{
|
{
|
||||||
fn cli_command(&self) -> Command {
|
fn cli_command(&self, ctx_ty: TypeId) -> Command {
|
||||||
self.handler.cli_command()
|
self.handler.cli_command(ctx_ty)
|
||||||
}
|
}
|
||||||
fn cli_parse(
|
fn cli_parse(
|
||||||
&self,
|
&self,
|
||||||
matches: &ArgMatches,
|
matches: &ArgMatches,
|
||||||
|
ctx_ty: TypeId,
|
||||||
) -> Result<(VecDeque<&'static str>, Value), clap::Error> {
|
) -> Result<(VecDeque<&'static str>, Value), clap::Error> {
|
||||||
self.handler.cli_parse(matches)
|
self.handler.cli_parse(matches, ctx_ty)
|
||||||
}
|
}
|
||||||
fn cli_display(&self, handle_args: HandleAnyArgs, result: Value) -> Result<(), RpcError> {
|
fn cli_display(&self, handle_args: HandleAnyArgs, result: Value) -> Result<(), RpcError> {
|
||||||
self.handler
|
self.handler
|
||||||
@@ -546,42 +549,49 @@ where
|
|||||||
Params: FromArgMatches + CommandFactory + Serialize,
|
Params: FromArgMatches + CommandFactory + Serialize,
|
||||||
InheritedParams: Serialize,
|
InheritedParams: Serialize,
|
||||||
{
|
{
|
||||||
fn cli_command(&self) -> Command {
|
fn cli_command(&self, ctx_ty: TypeId) -> Command {
|
||||||
// Params::command().subcommands(self.subcommands.0.iter().filter_map(|(name, handlers)| {
|
let mut base = Params::command();
|
||||||
// handlers.iter().find_map(|(ctx_ty, handler)| {
|
for (name, handlers) in &self.subcommands.0 {
|
||||||
// if let DynHandler::WithCli(h) = handler {
|
if let (Name(Some(name)), Some(DynHandler::WithCli(handler))) = (
|
||||||
// h.cli_command()
|
name,
|
||||||
// }
|
if let Some(handler) = handlers.get(&Some(ctx_ty)) {
|
||||||
// })
|
Some(handler)
|
||||||
// }))
|
} else if let Some(handler) = handlers.get(&None) {
|
||||||
todo!()
|
Some(handler)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
base = base.subcommand(handler.cli_command(ctx_ty).name(name));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
base
|
||||||
}
|
}
|
||||||
fn cli_parse(
|
fn cli_parse(
|
||||||
&self,
|
&self,
|
||||||
matches: &ArgMatches,
|
matches: &ArgMatches,
|
||||||
|
ctx_ty: TypeId,
|
||||||
) -> Result<(VecDeque<&'static str>, Value), clap::Error> {
|
) -> Result<(VecDeque<&'static str>, Value), clap::Error> {
|
||||||
// let root_params = imbl_value::to_value(&Params::from_arg_matches(matches)?)
|
let root_params = imbl_value::to_value(&Params::from_arg_matches(matches)?)
|
||||||
// .map_err(|e| clap::Error::raw(clap::error::ErrorKind::ValueValidation, e))?;
|
.map_err(|e| clap::Error::raw(clap::error::ErrorKind::ValueValidation, e))?;
|
||||||
// let (m, matches) = match matches.subcommand() {
|
let (name, matches) = match matches.subcommand() {
|
||||||
// Some((m, matches)) => (Some(m), matches),
|
Some((name, matches)) => (Some(name), matches),
|
||||||
// None => (None, matches),
|
None => (None, matches),
|
||||||
// };
|
};
|
||||||
// if let Some((SubcommandKey((_, m)), DynHandler::WithCli(h))) = self
|
if let Some((Name(Some(name)), DynHandler::WithCli(handler))) =
|
||||||
// .subcommands
|
self.subcommands.get(ctx_ty, name)
|
||||||
// .get_key_value(&(TypeId::of::<Context>(), m))
|
{
|
||||||
// {
|
let (mut method, params) = handler.cli_parse(matches, ctx_ty)?;
|
||||||
// let (mut method, params) = h.cli_parse(matches)?;
|
method.push_front(name);
|
||||||
// if let Some(m) = m {
|
|
||||||
// method.push_front(*m);
|
Ok((
|
||||||
// }
|
method,
|
||||||
// return Ok((
|
combine(root_params, params)
|
||||||
// method,
|
.map_err(|e| clap::Error::raw(clap::error::ErrorKind::ArgumentConflict, e))?,
|
||||||
// combine(root_params, params)
|
))
|
||||||
// .map_err(|e| clap::Error::raw(clap::error::ErrorKind::ArgumentConflict, e))?,
|
} else {
|
||||||
// ));
|
Ok((VecDeque::new(), root_params))
|
||||||
// }
|
}
|
||||||
// Ok((VecDeque::new(), root_params))
|
|
||||||
todo!()
|
|
||||||
}
|
}
|
||||||
fn cli_display(
|
fn cli_display(
|
||||||
&self,
|
&self,
|
||||||
@@ -594,27 +604,26 @@ where
|
|||||||
}: HandleArgs<AnyContext, Self>,
|
}: HandleArgs<AnyContext, Self>,
|
||||||
result: Self::Ok,
|
result: Self::Ok,
|
||||||
) -> Result<(), Self::Err> {
|
) -> Result<(), Self::Err> {
|
||||||
// let cmd = method.pop_front();
|
let cmd = method.pop_front();
|
||||||
// if let Some(cmd) = cmd {
|
if let Some(cmd) = cmd {
|
||||||
// parent_method.push(cmd);
|
parent_method.push(cmd);
|
||||||
// }
|
}
|
||||||
// if let Some(DynHandler::WithCli(sub_handler)) =
|
if let Some((_, DynHandler::WithCli(sub_handler))) =
|
||||||
// self.subcommands.get(&(context.inner_type_id(), cmd))
|
self.subcommands.get(context.inner_type_id(), cmd)
|
||||||
// {
|
{
|
||||||
// sub_handler.cli_display(
|
sub_handler.cli_display(
|
||||||
// HandleAnyArgs {
|
HandleAnyArgs {
|
||||||
// context: AnyContext::new(context),
|
context,
|
||||||
// parent_method,
|
parent_method,
|
||||||
// method,
|
method,
|
||||||
// params: imbl_value::to_value(&Flat(params, inherited_params))
|
params: imbl_value::to_value(&Flat(params, inherited_params))
|
||||||
// .map_err(invalid_params)?,
|
.map_err(invalid_params)?,
|
||||||
// },
|
},
|
||||||
// result,
|
result,
|
||||||
// )
|
)
|
||||||
// } else {
|
} else {
|
||||||
// Err(yajrc::METHOD_NOT_FOUND_ERROR)
|
Err(yajrc::METHOD_NOT_FOUND_ERROR)
|
||||||
// }
|
}
|
||||||
todo!()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user