root handler

This commit is contained in:
Aiden McClelland
2023-12-18 11:18:57 -07:00
parent 875d4beacb
commit 178790c674

View File

@@ -396,11 +396,7 @@ where
} }
impl<Params, InheritedParams> ParentHandler<Params, InheritedParams> { impl<Params, InheritedParams> ParentHandler<Params, InheritedParams> {
pub fn subcommand<Context, H>( pub fn subcommand<Context, H>(mut self, name: &'static str, handler: H) -> Self
mut self,
name: impl Into<Option<&'static str>>,
handler: H,
) -> Self
where where
Context: IntoContext, Context: IntoContext,
H: Handler<Context, InheritedParams = NoParams> + PrintCliResult<Context> + 'static, H: Handler<Context, InheritedParams = NoParams> + PrintCliResult<Context> + 'static,
@@ -421,11 +417,7 @@ impl<Params, InheritedParams> ParentHandler<Params, InheritedParams> {
); );
self self
} }
pub fn subcommand_no_cli<Context, H>( pub fn subcommand_no_cli<Context, H>(mut self, name: &'static str, handler: H) -> Self
mut self,
name: impl Into<Option<&'static str>>,
handler: H,
) -> Self
where where
Context: IntoContext, Context: IntoContext,
H: Handler<Context, InheritedParams = NoParams> + 'static, H: Handler<Context, InheritedParams = NoParams> + 'static,
@@ -451,7 +443,7 @@ where
{ {
pub fn subcommand_with_inherited<Context, H, F>( pub fn subcommand_with_inherited<Context, H, F>(
mut self, mut self,
name: impl Into<Option<&'static str>>, name: &'static str,
handler: H, handler: H,
inherit: F, inherit: F,
) -> Self ) -> Self
@@ -482,7 +474,7 @@ where
} }
pub fn subcommand_with_inherited_no_cli<Context, H, F>( pub fn subcommand_with_inherited_no_cli<Context, H, F>(
mut self, mut self,
name: impl Into<Option<&'static str>>, name: &'static str,
handler: H, handler: H,
inherit: F, inherit: F,
) -> Self ) -> Self
@@ -508,6 +500,55 @@ where
); );
self self
} }
pub fn root_handler<Context, H, F>(mut self, handler: H, inherit: F) -> Self
where
Context: IntoContext,
H: Handler<Context, Params = NoParams> + PrintCliResult<Context> + 'static,
H::Params: FromArgMatches + CommandFactory + Serialize + DeserializeOwned,
H::Ok: Serialize + DeserializeOwned,
RpcError: From<H::Err>,
F: Fn(Params, InheritedParams) -> H::InheritedParams + 'static,
{
self.subcommands.insert(
handler.contexts(),
None,
DynHandler::WithCli(Arc::new(AnyHandler {
_ctx: PhantomData,
handler: WithCliBindings {
_ctx: PhantomData,
handler: InheritanceHandler::<Context, Params, InheritedParams, H, F> {
_phantom: PhantomData,
handler,
inherit,
},
},
})),
);
self
}
pub fn root_handler_no_cli<Context, H, F>(mut self, handler: H, inherit: F) -> Self
where
Context: IntoContext,
H: Handler<Context, Params = NoParams> + 'static,
H::Params: DeserializeOwned,
H::Ok: Serialize,
RpcError: From<H::Err>,
F: Fn(Params, InheritedParams) -> H::InheritedParams + 'static,
{
self.subcommands.insert(
handler.contexts(),
None,
DynHandler::WithoutCli(Arc::new(AnyHandler {
_ctx: PhantomData,
handler: InheritanceHandler::<Context, Params, InheritedParams, H, F> {
_phantom: PhantomData,
handler,
inherit,
},
})),
);
self
}
} }
impl<Params: Serialize, InheritedParams: Serialize> Handler<AnyContext> impl<Params: Serialize, InheritedParams: Serialize> Handler<AnyContext>