add line in index
This commit is contained in:
parent
f1724d23f5
commit
48286c69b4
@ -1,5 +1,8 @@
|
|||||||
use clap::Values;
|
use clap::Values;
|
||||||
|
use std::fs::OpenOptions;
|
||||||
use crate::utils;
|
use crate::utils;
|
||||||
|
use std::path::Path;
|
||||||
|
use std::io::Write
|
||||||
|
|
||||||
pub fn add(files: Values<'_>) {
|
pub fn add(files: Values<'_>) {
|
||||||
let root = match utils::path::nextsync_root() {
|
let root = match utils::path::nextsync_root() {
|
||||||
@ -10,9 +13,33 @@ pub fn add(files: Values<'_>) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
dbg!(root.clone());
|
let mut index_path = root.clone();
|
||||||
|
index_path.push(".nextsync");
|
||||||
|
index_path.push("index");
|
||||||
|
let mut index_file = OpenOptions::new()
|
||||||
|
.read(true)
|
||||||
|
.write(true)
|
||||||
|
.append(true)
|
||||||
|
.create(true)
|
||||||
|
.open(index_path).expect("Cannot open index file");
|
||||||
|
|
||||||
let file_vec: Vec<&str> = files.collect();
|
let file_vec: Vec<&str> = files.collect();
|
||||||
for file in file_vec {
|
for file in file_vec {
|
||||||
|
let path = Path::new(file);
|
||||||
println!("{}", file);
|
println!("{}", file);
|
||||||
|
match path.try_exists() {
|
||||||
|
Ok(true) => {
|
||||||
|
match writeln!(index_file, "{}", path.display()) {
|
||||||
|
Ok(()) => (),
|
||||||
|
Err(err) => eprintln!("{}", err),
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Ok(false) => {
|
||||||
|
// todo can be regex
|
||||||
|
},
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!("Error: {}", err);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user