1#[path = "../src/flush.rs"]
2mod flush;
3
4use std::{env, fs, io::Write, path::Path};
5fn main() -> Result<(), Box<dyn std::error::Error>> {
6 let args: Vec<_> = env::args().skip(1).collect();
7 if args.len() != 3 {
8 return Err("Usage: create_notebook DIRECTORY TEXT AUTHOR".into());
9 }
10 let section = onestore::create_section("synthetic.one", &args[1], &args[2])?;
11 let identity = onestore::Store::parse(&section)?.header.file_id;
12 let toc = onestore::create_table_of_contents(
13 "Open Notebook.onetoc2",
14 &[("synthetic.one", identity)],
15 )?;
16 fs::create_dir(&args[0])?;
17 for (name, data) in [("synthetic.one", section), ("Open Notebook.onetoc2", toc)] {
18 let mut file = fs::OpenOptions::new()
19 .create_new(true)
20 .write(true)
21 .open(Path::new(&args[0]).join(name))?;
22 file.write_all(&data)?;
23 flush::flush(&file)?;
24 }
25 Ok(())
26}