~calmbit/suki

87b1224afee173ac4696a2188407d3fbc0b79364 — CalmBit 6 months ago e669785
first pass at removal
1 files changed, 24 insertions(+), 1 deletions(-)

M src/main.rs
M src/main.rs => src/main.rs +24 -1
@@ 23,7 23,10 @@ fn main() -> Result<(), String> {
                None => Err(String::from("no filename supplied to tag")),
            }
        
        "r" | "remove" => Err(format!("unimplemented cmd - remove")),
        "r" | "remove" => match args.get(2) {
            Some(s) => remove(s, args.split_at(3).1),
            None => Err(String::from("no filename supplied to remove")),
        }
        "s" | "search" => Err(format!("unimplemented cmd - search")),
        "h" | "help" => {
            print_help();


@@ 65,6 68,26 @@ fn tag(filename: &str, tags: &[String]) -> Result<(), String> {
    file.serialize("contrib")
}

fn remove(filename: &str, tags: &[String]) -> Result<(), String> {
    let dir = curr_dir();
    println!("file: {}, tags: {:?}", filename, tags);

    let mut file = suki::SukiFile::new(&dir)?;

    if !tags.is_empty() {
        for t in tags {
            for st in &mut file.tags {
                if t.eq(&st.tag) {
                    st.files.retain(|f| !f.eq(filename));
                    break;
                }
            } 
        }
    }

    file.serialize("contrib")
}

fn print_version() {
    println!(
        "{} version {} - the simple unique krap itemizer",