use rusqlite::Connection;
use std::io::Write;
use std::io::stdin; use std::io::stdout; use to_do_cli::db::init_db;
fn runprompt(conn: &Connection) {
loop {
let mut output = stdout();
print!("(ToDo list) > "); output
.flush() .expect("can't flush the stdout");
let mut buffer = String::new(); stdin()
.read_line(&mut buffer) .expect("Cannot readline");
let args: Vec<&str> = buffer
.split_whitespace() .collect();
if args.is_empty() {
continue;
}
match to_do_cli::parse_arguments(&conn, args) {
Ok(()) => {}
Err(e) => eprintln!("Error: {:?}", e),
}
}
}
fn main() {
let conn = init_db().expect("Failed to initialize the database");
runprompt(&conn); }