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
mod cli;
mod command;
mod helper;
mod print;
use {
crate::cli::Cli,
clap::Parser,
gluesql_core::store::{GStore, GStoreMut},
gluesql_memory_storage::MemoryStorage,
gluesql_sled_storage::SledStorage,
std::{fmt::Debug, path::PathBuf},
};
#[derive(Parser, Debug)]
#[clap(name = "gluesql", about, version)]
struct Args {
#[clap(short, long, parse(from_os_str))]
path: Option<PathBuf>,
}
pub fn run() {
let args = Args::parse();
if let Some(path) = args.path {
let path = path.as_path().to_str().expect("wrong path");
println!("[sled-storage] connected to {}", path);
run(SledStorage::new(path).expect("failed to load sled-storage"));
} else {
println!("[memory-storage] initialized");
run(MemoryStorage::default());
}
fn run<T: Debug, U: GStore<T> + GStoreMut<T>>(storage: U) {
let output = std::io::stdout();
let mut cli = Cli::new(storage, output);
if let Err(e) = cli.run() {
eprintln!("{}", e);
}
}
}