mirror of
https://github.com/PR0M3TH3AN/Marlin.git
synced 2025-09-09 15:48:43 +00:00
update
This commit is contained in:
23
src/cli.rs
23
src/cli.rs
@@ -9,11 +9,11 @@ pub mod annotate;
|
||||
pub mod version;
|
||||
pub mod event;
|
||||
|
||||
use clap::{Parser, Subcommand, ArgEnum, Args, CommandFactory};
|
||||
use clap::{Parser, Subcommand, CommandFactory, ValueEnum};
|
||||
use clap_complete::Shell;
|
||||
|
||||
/// Output format for commands.
|
||||
#[derive(ArgEnum, Clone, Copy, Debug)]
|
||||
#[derive(ValueEnum, Clone, Copy, Debug)]
|
||||
pub enum Format {
|
||||
Text,
|
||||
Json,
|
||||
@@ -78,45 +78,46 @@ pub enum Commands {
|
||||
/// Generate shell completions (hidden)
|
||||
#[command(hide = true)]
|
||||
Completions {
|
||||
/// Which shell to generate for
|
||||
#[arg(value_enum)]
|
||||
shell: Shell,
|
||||
},
|
||||
|
||||
/// File-to-file links
|
||||
#[command(subcommand)]
|
||||
Link { cmd: link::LinkCmd },
|
||||
Link(link::LinkCmd),
|
||||
|
||||
/// Collections (groups) of files
|
||||
#[command(subcommand)]
|
||||
Coll { cmd: coll::CollCmd },
|
||||
Coll(coll::CollCmd),
|
||||
|
||||
/// Smart views (saved queries)
|
||||
#[command(subcommand)]
|
||||
View { cmd: view::ViewCmd },
|
||||
View(view::ViewCmd),
|
||||
|
||||
/// Workflow states on files
|
||||
#[command(subcommand)]
|
||||
State { cmd: state::StateCmd },
|
||||
State(state::StateCmd),
|
||||
|
||||
/// TODO/tasks management
|
||||
#[command(subcommand)]
|
||||
Task { cmd: task::TaskCmd },
|
||||
Task(task::TaskCmd),
|
||||
|
||||
/// Reminders on files
|
||||
#[command(subcommand)]
|
||||
Remind { cmd: remind::RemindCmd },
|
||||
Remind(remind::RemindCmd),
|
||||
|
||||
/// File annotations and highlights
|
||||
#[command(subcommand)]
|
||||
Annotate { cmd: annotate::AnnotateCmd },
|
||||
Annotate(annotate::AnnotateCmd),
|
||||
|
||||
/// Version diffs
|
||||
#[command(subcommand)]
|
||||
Version { cmd: version::VersionCmd },
|
||||
Version(version::VersionCmd),
|
||||
|
||||
/// Calendar events & timelines
|
||||
#[command(subcommand)]
|
||||
Event { cmd: event::EventCmd },
|
||||
Event(event::EventCmd),
|
||||
}
|
||||
|
||||
#[derive(Subcommand, Debug)]
|
||||
|
38
src/main.rs
38
src/main.rs
@@ -6,7 +6,7 @@ mod logging;
|
||||
mod scan;
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use clap::{Parser, Subcommand};
|
||||
use clap::{Parser, Subcommand, CommandFactory};
|
||||
use clap_complete::{generate, Shell};
|
||||
use glob::Pattern;
|
||||
use rusqlite::params;
|
||||
@@ -26,10 +26,11 @@ fn main() -> Result<()> {
|
||||
}
|
||||
logging::init();
|
||||
|
||||
// Handle shell completions as a hidden command
|
||||
if let Commands::Completions { shell } = args.command {
|
||||
// If the user asked for completions, generate and exit immediately.
|
||||
if let Commands::Completions { shell } = &args.command {
|
||||
let mut cmd = Cli::command();
|
||||
generate(shell, &mut cmd, "marlin", &mut io::stdout());
|
||||
// Shell is Copy so we can deref it safely
|
||||
generate(*shell, &mut cmd, "marlin", &mut io::stdout());
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
@@ -47,8 +48,11 @@ fn main() -> Result<()> {
|
||||
// Open (and migrate) the DB
|
||||
let mut conn = db::open(&cfg.db_path)?;
|
||||
|
||||
// Dispatch
|
||||
// Dispatch all commands
|
||||
match args.command {
|
||||
Commands::Completions { .. } => {
|
||||
// no-op, already handled above
|
||||
}
|
||||
Commands::Init => {
|
||||
info!("Database initialised at {}", cfg.db_path.display());
|
||||
}
|
||||
@@ -90,15 +94,15 @@ fn main() -> Result<()> {
|
||||
info!("Successfully opened restored database.");
|
||||
}
|
||||
// new domains delegate to their run() functions
|
||||
Commands::Link { cmd } => cli::link::run(&cmd, &mut conn, args.format)?,
|
||||
Commands::Coll { cmd } => cli::coll::run(&cmd, &mut conn, args.format)?,
|
||||
Commands::View { cmd } => cli::view::run(&cmd, &mut conn, args.format)?,
|
||||
Commands::State { cmd } => cli::state::run(&cmd, &mut conn, args.format)?,
|
||||
Commands::Task { cmd } => cli::task::run(&cmd, &mut conn, args.format)?,
|
||||
Commands::Remind { cmd } => cli::remind::run(&cmd, &mut conn, args.format)?,
|
||||
Commands::Annotate { cmd } => cli::annotate::run(&cmd, &mut conn, args.format)?,
|
||||
Commands::Version { cmd } => cli::version::run(&cmd, &mut conn, args.format)?,
|
||||
Commands::Event { cmd } => cli::event::run(&cmd, &mut conn, args.format)?,
|
||||
Commands::Link(link_cmd) => cli::link::run(&link_cmd, &mut conn, args.format)?,
|
||||
Commands::Coll(coll_cmd) => cli::coll::run(&coll_cmd, &mut conn, args.format)?,
|
||||
Commands::View(view_cmd) => cli::view::run(&view_cmd, &mut conn, args.format)?,
|
||||
Commands::State(state_cmd) => cli::state::run(&state_cmd, &mut conn, args.format)?,
|
||||
Commands::Task(task_cmd) => cli::task::run(&task_cmd, &mut conn, args.format)?,
|
||||
Commands::Remind(rm_cmd) => cli::remind::run(&rm_cmd, &mut conn, args.format)?,
|
||||
Commands::Annotate(an_cmd) => cli::annotate::run(&an_cmd, &mut conn, args.format)?,
|
||||
Commands::Version(v_cmd) => cli::version::run(&v_cmd, &mut conn, args.format)?,
|
||||
Commands::Event(e_cmd) => cli::event::run(&e_cmd, &mut conn, args.format)?,
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -117,7 +121,11 @@ fn apply_tag(conn: &rusqlite::Connection, pattern: &str, tag_path: &str) -> Resu
|
||||
conn.prepare("INSERT OR IGNORE INTO file_tags(file_id, tag_id) VALUES (?1, ?2)")?;
|
||||
|
||||
let mut count = 0;
|
||||
for entry in WalkDir::new(&root).into_iter().filter_map(Result::ok).filter(|e| e.file_type().is_file()) {
|
||||
for entry in WalkDir::new(&root)
|
||||
.into_iter()
|
||||
.filter_map(Result::ok)
|
||||
.filter(|e| e.file_type().is_file())
|
||||
{
|
||||
let path_str = entry.path().to_string_lossy();
|
||||
debug!("testing path: {}", path_str);
|
||||
if !pat.matches(&path_str) {
|
||||
|
Reference in New Issue
Block a user