Move option parsing logic from src/delete/main.rs to newly introduced delete::cli module.

Changes:
- Introduce "delete::cli" module in "hagrid" crate.
- Move option parsing logic there from src/delete/main.rs (former src/delete.rs).
This commit is contained in:
Zeke Fast
2025-05-03 11:33:06 +02:00
parent d35136b0d6
commit abeafbe3d4
2 changed files with 29 additions and 28 deletions

25
src/delete/cli.rs Normal file
View File

@@ -0,0 +1,25 @@
use structopt::StructOpt;
use std::path::PathBuf;
#[derive(Debug, StructOpt)]
#[structopt(
name = "hagrid-delete",
about = "Deletes (address, key)-binding(s), and/or a key(s)."
)]
pub(crate) struct Opt {
/// Base directory.
#[structopt(parse(from_os_str))]
pub(crate) base: PathBuf,
/// E-Mail address, Fingerprint, or KeyID of the TPK to delete.
/// If a Fingerprint or KeyID is given, --all is implied.
pub(crate) query: String,
/// Also delete all bindings.
#[structopt(long = "all-bindings")]
pub(crate) all_bindings: bool,
/// Also delete all bindings and the key.
#[structopt(long = "all")]
pub(crate) all: bool,
}

View File

@@ -1,34 +1,10 @@
//! Deletes (address, key)-binding(s), and/or a key(s).
mod cli;
use std::convert::TryInto;
use std::path::PathBuf;
use structopt::StructOpt;
use hagrid_database::{Database, KeyDatabase, Query, types::Fingerprint};
#[derive(Debug, StructOpt)]
#[structopt(
name = "hagrid-delete",
about = "Deletes (address, key)-binding(s), and/or a key(s)."
)]
pub struct Opt {
/// Base directory.
#[structopt(parse(from_os_str))]
base: PathBuf,
/// E-Mail address, Fingerprint, or KeyID of the TPK to delete.
/// If a Fingerprint or KeyID is given, --all is implied.
query: String,
/// Also delete all bindings.
#[structopt(long = "all-bindings")]
all_bindings: bool,
/// Also delete all bindings and the key.
#[structopt(long = "all")]
all: bool,
}
use hagrid_database::{types::Fingerprint, Database, KeyDatabase, Query};
fn main() {
if let Err(e) = real_main() {
@@ -44,7 +20,7 @@ fn main() {
}
fn real_main() -> anyhow::Result<()> {
let opt = Opt::from_args();
let opt = cli::Opt::from_args();
let db = KeyDatabase::new_file(opt.base.canonicalize()?)?;
delete(&db, &opt.query.parse()?, opt.all_bindings, opt.all)
}