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 std::fs;
use std::io::{self, Write};
use std::io::{self, Write, BufRead};
use std::path::Path;
@ -26,7 +26,10 @@ enum Commands {
Add {
#[arg(value_name="item_id")]
input: String
}
},
/// Lists all ids stored in db
List
}
@ -56,6 +59,23 @@ fn add() -> io::Result<()> {
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<()> {
let cli = Cli::parse();
match &cli.command {
@ -66,6 +86,9 @@ fn main() -> io::Result<()> {
Some(Commands::Add{..}) => {
add()?;
}
Some(Commands::List) => {
list()?;
}
None => {
if !is_inited() {
println!("Do you want to init your storage? [Y/n]");

Loading…
Cancel
Save