mirror of
https://gitlab.com/keys.openpgp.org/hagrid.git
synced 2025-10-06 00:23:08 +02:00
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:
25
src/delete/cli.rs
Normal file
25
src/delete/cli.rs
Normal 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,
|
||||
}
|
@@ -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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user