diff --git a/src/db.rs b/src/db.rs index 93b044c..64242cb 100644 --- a/src/db.rs +++ b/src/db.rs @@ -18,7 +18,8 @@ impl Item { pub fn from(s: String, c: String) -> Item { Item { id: s, content: c } } - pub fn from_d(s: String) -> Item { + // used only to search in HashSet + pub fn from_empty(s: String) -> Item { Item { id: s, content: String::from("") } } } @@ -101,8 +102,7 @@ impl DB { } pub fn contains(&self, id: &String) -> bool { - // TODO: check with content - let item = Item::from_d(id.clone()); + let item = Item::from_empty(id.clone()); self.items.contains(&item) } diff --git a/src/main.rs b/src/main.rs index 62f61ec..7aacfe0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,6 +11,7 @@ use clap::{Parser, Subcommand}; use std::fs; use std::io::{self, Write}; use std::path::Path; +use std::process; static STORAGE_FOLDER: &str = "storage"; @@ -114,7 +115,7 @@ fn get_prompt(question: &str) -> io::Result { } -fn main() -> io::Result<()> { +fn run_command() -> io::Result<()> { let cli = Cli::parse(); match &cli.command { Some(Commands::Init) => { @@ -144,3 +145,14 @@ fn main() -> io::Result<()> { } Ok(()) } + +fn main() { + match run_command() { + Ok(()) => return, + Err(e) => { + println!("{}", e); + process::exit(2); // TODO: better codes for different errors + } + } + +}