1pub mod certificate;
3pub mod serve;
5
6use bonsaidb_local::cli::StorageCommand;
7use clap::Parser;
8
9use crate::{Backend, BackendError, CustomServer, NoBackend, ServerConfiguration};
10
11#[derive(Parser, Debug)]
13pub enum Command<B: Backend = NoBackend> {
14 #[clap(subcommand)]
16 Certificate(certificate::Command),
17
18 Serve(serve::Serve<B>),
20
21 #[clap(flatten)]
23 Storage(StorageCommand),
24}
25
26impl<B: Backend> Command<B> {
27 pub async fn execute(
29 self,
30 configuration: ServerConfiguration<B>,
31 ) -> Result<(), BackendError<B::Error>> {
32 let server = CustomServer::<B>::open(configuration).await?;
33 self.execute_on(server).await
34 }
35
36 pub async fn execute_on(self, server: CustomServer<B>) -> Result<(), BackendError<B::Error>> {
38 match self {
39 Self::Certificate(command) => command.execute(&server).await,
40 Self::Serve(command) => command.execute(&server).await,
41 Self::Storage(command) => command
42 .execute_on_async(&server)
43 .await
44 .map_err(BackendError::from),
45 }
46 }
47}