mirror of
https://github.com/PR0M3TH3AN/Marlin.git
synced 2025-09-09 15:48:43 +00:00
update
This commit is contained in:
14
src/cli.rs
14
src/cli.rs
@@ -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,
|
||||
|
17
src/main.rs
17
src/main.rs
@@ -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)?;
|
||||
}
|
||||
|
Reference in New Issue
Block a user