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
37
38
39
40
41
42
43
44
45
46
47
48
pub mod certificate;
pub mod serve;
use std::path::{Path, PathBuf};
use structopt::StructOpt;
use crate::{Configuration, Server};
#[derive(StructOpt, Debug)]
pub struct Cli {
pub server_data_directory: PathBuf,
#[structopt(subcommand)]
pub subcommand: Command,
}
#[derive(StructOpt, Debug)]
pub enum Command {
Certificate(certificate::Command),
#[structopt(flatten)]
Serve(serve::Serve),
}
impl Command {
pub async fn execute<F: Fn(&Server) + Send>(
&self,
database_path: &Path,
schema_registrar: F,
) -> anyhow::Result<()> {
let server = Server::open(database_path, Configuration::default()).await?;
schema_registrar(&server);
match self {
Self::Certificate(command) => command.execute(server).await,
Self::Serve(command) => command.execute(server).await,
}
}
}