Browse Source

basic list

db-refactoring
Coin de Gamma 4 months ago
parent
commit
bd70695b77
  1. 27
      src/main.rs

27
src/main.rs

@ -1,7 +1,7 @@
use clap::{Parser, Subcommand}; use clap::{Parser, Subcommand};
use std::fs; use std::fs;
use std::io::{self, Write}; use std::io::{self, Write, BufRead};
use std::path::Path; use std::path::Path;
@ -26,7 +26,10 @@ enum Commands {
Add { Add {
#[arg(value_name="item_id")] #[arg(value_name="item_id")]
input: String input: String
} },
/// Lists all ids stored in db
List
} }
@ -56,6 +59,23 @@ fn add() -> io::Result<()> {
Ok(()) Ok(())
} }
// TODO: make this ti return just set on values, will need later to check ids
fn list() -> io:: Result<()> {
let file = fs::File::open(STORAGE_PATH)?;
let reader = io::BufReader::new(file);
for line in reader.lines() {
match line {
Ok(content) => {
println!("{}", content)
},
Err(e) => {
eprintln!("Error reading line , {}", e);
}
}
}
Ok(())
}
fn main() -> io::Result<()> { fn main() -> io::Result<()> {
let cli = Cli::parse(); let cli = Cli::parse();
match &cli.command { match &cli.command {
@ -66,6 +86,9 @@ fn main() -> io::Result<()> {
Some(Commands::Add{..}) => { Some(Commands::Add{..}) => {
add()?; add()?;
} }
Some(Commands::List) => {
list()?;
}
None => { None => {
if !is_inited() { if !is_inited() {
println!("Do you want to init your storage? [Y/n]"); println!("Do you want to init your storage? [Y/n]");

Loading…
Cancel
Save