Browse Source

errors print better

db-refactoring
Coin de Gamma 3 months ago
parent
commit
ee2c2faeba
  1. 6
      src/db.rs
  2. 14
      src/main.rs

6
src/db.rs

@ -18,7 +18,8 @@ impl Item {
pub fn from(s: String, c: String) -> Item { pub fn from(s: String, c: String) -> Item {
Item { id: s, content: c } 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("") } Item { id: s, content: String::from("") }
} }
} }
@ -101,8 +102,7 @@ impl DB {
} }
pub fn contains(&self, id: &String) -> bool { pub fn contains(&self, id: &String) -> bool {
// TODO: check with content let item = Item::from_empty(id.clone());
let item = Item::from_d(id.clone());
self.items.contains(&item) self.items.contains(&item)
} }

14
src/main.rs

@ -11,6 +11,7 @@ use clap::{Parser, Subcommand};
use std::fs; use std::fs;
use std::io::{self, Write}; use std::io::{self, Write};
use std::path::Path; use std::path::Path;
use std::process;
static STORAGE_FOLDER: &str = "storage"; static STORAGE_FOLDER: &str = "storage";
@ -114,7 +115,7 @@ fn get_prompt(question: &str) -> io::Result<PROMPT> {
} }
fn main() -> io::Result<()> { fn run_command() -> io::Result<()> {
let cli = Cli::parse(); let cli = Cli::parse();
match &cli.command { match &cli.command {
Some(Commands::Init) => { Some(Commands::Init) => {
@ -144,3 +145,14 @@ fn main() -> io::Result<()> {
} }
Ok(()) Ok(())
} }
fn main() {
match run_command() {
Ok(()) => return,
Err(e) => {
println!("{}", e);
process::exit(2); // TODO: better codes for different errors
}
}
}

Loading…
Cancel
Save