pub struct Commands<S> { /* private fields */ }Expand description
Houses your commands. See CommandHandler for more details
§Note
Your handler will only be called if it could match your CommandHandler::args().
To run commands, you need to have a second binary which does the same (or calls) the [crate::Quokka::execute_command] function.
Running the [crate::Quokka::serve] in a subcommand could possibly also work, but this is something I have not tested and sounds somewhat wrong.
§Example
use quokka_command::{Commands, CommandHandler, Result, Error};
use quokka_state::FromState;
use clap::Command;
#[derive(Clone)]
struct TestState;
struct TestHandler;
impl<S> FromState<S> for TestHandler {
fn from_state(input: &S) -> Self {
Self
}
}
impl CommandHandler for TestHandler {
type Error = Error;
fn args() -> clap::Command {
Command::new("test-command")
}
async fn call(self, _: clap::ArgMatches) -> Result<()> {
Ok(())
}
}
let mut cmds = Commands::default();
cmds.register_command::<TestHandler>();
cmds.dispatch(TestState, ["test-command"]);
Implementations§
Source§impl<S: Send + Sync + Clone + 'static> Commands<S>
impl<S: Send + Sync + Clone + 'static> Commands<S>
pub fn register_command<C: CommandHandler + 'static>(&mut self)where
S: ProvideState<C>,
pub async fn dispatch<I, T>(self, state: S, args: I) -> Result<()>
pub fn build_clap_command(&self) -> Command
Trait Implementations§
Auto Trait Implementations§
impl<S> Freeze for Commands<S>
impl<S> RefUnwindSafe for Commands<S>
impl<S> Send for Commands<S>
impl<S> Sync for Commands<S>
impl<S> Unpin for Commands<S>
impl<S> UnwindSafe for Commands<S>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more