pub mod certificate;
pub mod serve;
use bonsaidb_local::cli::StorageCommand;
use clap::Parser;
use crate::{Backend, BackendError, CustomServer, NoBackend, ServerConfiguration};
#[derive(Parser, Debug)]
pub enum Command<B: Backend = NoBackend> {
#[clap(subcommand)]
Certificate(certificate::Command),
Serve(serve::Serve<B>),
#[clap(flatten)]
Storage(StorageCommand),
}
impl<B: Backend> Command<B> {
pub async fn execute(
self,
configuration: ServerConfiguration<B>,
) -> Result<(), BackendError<B::Error>> {
let server = CustomServer::<B>::open(configuration).await?;
self.execute_on(server).await
}
pub async fn execute_on(self, server: CustomServer<B>) -> Result<(), BackendError<B::Error>> {
match self {
Self::Certificate(command) => command.execute(&server).await,
Self::Serve(command) => command.execute(&server).await,
Self::Storage(command) => command
.execute_on_async(&server)
.await
.map_err(BackendError::from),
}
}
}