Repository navigation
Expand file tree
/
Copy pathmain.rs
More file actions
50 lines (44 loc) · 1.54 KB
/
Copy pathmain.rs
File metadata and controls
50 lines (44 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
6AE9
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
49
50
#[cfg(any(not(target_arch = "wasm32"), target_os = "wasi"))]
use minigraf::Minigraf;
#[cfg(not(target_arch = "wasm32"))]
use minigraf::OpenOptions;
fn main() -> anyhow::Result<()> {
#[cfg(target_os = "wasi")]
{
let db = Minigraf::in_memory()?;
db.repl().run();
Ok(())
}
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
{
// Browser WASM — entry point is the BrowserDb JS/WASM API, not a REPL binary.
Ok(())
}
#[cfg(not(target_arch = "wasm32"))]
{
let args: Vec<String> = std::env::args().collect();
let file_flag_pos = args.iter().position(|a| a == "--file");
let db_path = file_flag_pos.and_then(|i| args.get(i + 1)).cloned();
let init_flag_pos = args.iter().position(|a| a == "--init");
let init_path = init_flag_pos.and_then(|i| args.get(i + 1)).cloned();
if file_flag_pos.is_some() && db_path.is_none() {
eprintln!("error: --file requires a path argument");
std::process::exit(1);
}
if init_flag_pos.is_some() && init_path.is_none() {
eprintln!("error: --init requires a path argument");
std::process::exit(1);
}
let db = if let Some(path) = db_path {
OpenOptions::new().path(path).open()?
} else {
Minigraf::in_memory()?
};
let repl = db.repl();
if let Some(path) = init_path {
repl.run_with_init(std::path::Path::new(&path));
}
repl.run();
Ok(())
}
}