This commit is contained in:
thePR0M3TH3AN
2025-05-14 16:21:00 -04:00
parent e63be17f9a
commit ebe9fa6e5c
6 changed files with 122 additions and 69 deletions

View File

@@ -14,12 +14,20 @@ pub struct Cli {
pub enum Commands {
/// Initialise the database (idempotent)
Init,
/// Scan a directory and populate the file index
/// Scan one or more directories and populate the file index
///
/// Example:
/// marlin scan ~/Pictures ~/Documents ~/Downloads
Scan {
/// Directory to walk
path: PathBuf,
/// One or more directories to walk
paths: Vec<PathBuf>,
},
/// Tag files matching a glob pattern
///
/// Example:
/// marlin tag "~/Pictures/**/*.jpg" vacation
Tag {
/// Glob pattern (quote to avoid shell expansion)
pattern: String,

View File

@@ -5,7 +5,7 @@ mod logging;
mod scan;
use anyhow::Result;
use clap::Parser; // 👈 bring in the trait that adds `.parse()`
use clap::Parser;
use cli::{Cli, Commands};
use glob::glob;
use rusqlite::params;
@@ -14,17 +14,24 @@ use tracing::{error, info};
fn main() -> Result<()> {
logging::init();
let args = Cli::parse(); // now compiles
let args = Cli::parse();
let cfg = config::Config::load()?;
let mut conn = db::open(&cfg.db_path)?; // mutable
let mut conn = db::open(&cfg.db_path)?;
match args.command {
Commands::Init => {
info!("database initialised at {}", cfg.db_path.display());
}
Commands::Scan { path } => {
scan::scan_directory(&mut conn, &path)?; // pass &mut
Commands::Scan { paths } => {
if paths.is_empty() {
anyhow::bail!("At least one directory must be supplied to `scan`");
}
for path in paths {
scan::scan_directory(&mut conn, &path)?;
}
}
Commands::Tag { pattern, tag } => {
apply_tag(&conn, &pattern, &tag)?;
}