This commit is contained in:
2023-11-14 21:12:13 -08:00
parent da15ef0f15
commit 98df04527d
6 changed files with 199 additions and 29 deletions

View File

@@ -6,6 +6,8 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
anyhow = "1.0.75"
clap = { version = "4.4.7", features = ["derive"] }
log = "0.4.14"
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0", features = ["unbounded_depth"] }

46
notmuch/src/main.rs Normal file
View File

@@ -0,0 +1,46 @@
use std::path::PathBuf;
use clap::{Parser, Subcommand};
use notmuch::Notmuch;
#[derive(Parser)]
#[command(author, version, about, long_about = None)]
#[command(propagate_version = true)]
struct Cli {
/// Optional notmuch config file
#[arg(short, long)]
config: Option<PathBuf>,
#[command(subcommand)]
command: Commands,
}
#[derive(Subcommand)]
enum Commands {
/// Show given search term
Show { search_term: String },
/// Search for given search term
Search { search_term: String },
}
fn main() -> anyhow::Result<()> {
let cli = Cli::parse();
let nm = if let Some(config_path) = cli.config {
Notmuch::with_config(config_path)
} else {
Notmuch::default()
};
// You can check for the existence of subcommands, and if found use their
// matches just as you would the top level cmd
match &cli.command {
Commands::Search { search_term } => {
println!("{:#?}", nm.search(&search_term, 0, 10)?);
}
Commands::Show { search_term } => {
println!("{:#?}", nm.show(&search_term)?);
}
}
Ok(())
}