Browse Source

add id

db-refactoring
Coin de Gamma 4 months ago
parent
commit
10bd6772fa
  1. 15
      src/main.rs

15
src/main.rs

@ -25,7 +25,7 @@ enum Commands {
/// Adds new item with unique id to the db
Add {
#[arg(value_name="item_id")]
input: String
id: String
},
/// Lists all ids stored in db
@ -47,19 +47,21 @@ fn init() -> io::Result<()> {
fs::File::create(STORAGE_PATH)?;
println!("Storage db created");
println!("Initialization complete. It's required to add folder `{}` under git manually.", STORAGE_FOLDER);
Ok(())
}
fn add() -> io::Result<()> {
fn add(id: &String) -> io::Result<()> {
let mut file = fs::OpenOptions::new()
.write(true)
.append(true)
.open(STORAGE_PATH)?;
writeln!(file, "new item")?;
writeln!(file, "{}", id)?;
Ok(())
}
// TODO: make this ti return just set on values, will need later to check ids
// TODO: make this to 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);
@ -81,10 +83,9 @@ fn main() -> io::Result<()> {
match &cli.command {
Some(Commands::Init) => {
init()?;
println!("Initialization complete");
}
Some(Commands::Add{..}) => {
add()?;
Some(Commands::Add{ id }) => {
add(id)?;
}
Some(Commands::List) => {
list()?;

Loading…
Cancel
Save