doclib 0.1.0

Tag-indexed CLI catalog for books and articles, with rclone-backed storage
use anyhow::Result;
use rusqlite::Connection;

use crate::db;
use crate::model::Kind;
use crate::ui;

pub fn run(conn: &Connection, tag: Option<&str>, kind: Option<Kind>) -> Result<()> {
    let docs = db::list(conn, tag, kind)?;
    ui::print_table(&docs);
    Ok(())
}

pub fn tags(conn: &Connection) -> Result<()> {
    let counts = db::tag_counts(conn)?;
    if counts.is_empty() {
        println!("no tags yet.");
        return Ok(());
    }
    for (name, uses) in &counts {
        println!("{}  {uses}", ui::truncate(name, 24));
    }
    Ok(())
}