From ee2c2faebac8fec2a87d79408a73c7dd6888d496 Mon Sep 17 00:00:00 2001 From: Coin de Gamma Date: Mon, 16 Sep 2024 14:49:14 +0000 Subject: [PATCH] errors print better --- src/db.rs | 6 +++--- src/main.rs | 14 +++++++++++++- 2 files changed, 16 insertions(+), 4 deletions(-) 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 + } + } + +}