1
/// Command-line interface for managing the root certificate.
2
pub mod certificate;
3
/// Command-line interface for hosting a server.
4
pub mod serve;
5

            
6
use bonsaidb_local::cli::StorageCommand;
7
use clap::Parser;
8

            
9
use crate::{Backend, CustomServer, Error, NoBackend, ServerConfiguration};
10

            
11
/// Available commands for `bonsaidb server`.
12
9
#[derive(Parser, Debug)]
13
pub enum Command<B: Backend = NoBackend> {
14
    /// Manage the server's root certificate.
15
    #[clap(subcommand)]
16
    Certificate(certificate::Command),
17

            
18
    /// Execute the server.
19
    Serve(serve::Serve<B>),
20

            
21
    /// Manage the server's storage.
22
    #[clap(flatten)]
23
    Storage(StorageCommand),
24
}
25

            
26
impl<B: Backend> Command<B> {
27
    /// Executes the command.
28
4
    pub async fn execute(&self, configuration: ServerConfiguration) -> Result<(), Error> {
29
70
        let server = CustomServer::<B>::open(configuration).await?;
30
4
        match self {
31
8
            Self::Certificate(command) => command.execute(&server).await,
32
6
            Self::Serve(command) => command.execute(&server).await,
33
77
            Self::Storage(command) => command.execute_on(&server).await.map_err(Error::from),
34
        }
35
3
    }
36
}