1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
pub mod certificate;
pub mod serve;
use bonsaidb_local::cli::StorageCommand;
use clap::Parser;
use crate::{Backend, CustomServer, Error, 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) -> Result<(), Error> {
        let server = CustomServer::<B>::open(configuration).await?;
        match self {
            Self::Certificate(command) => command.execute(&server).await,
            Self::Serve(command) => command.execute(&server).await,
            Self::Storage(command) => command.execute_on(&server).await.map_err(Error::from),
        }
    }
}