Skip to content

Commit

Permalink
Added placeholders for new dedupe code.
Browse files Browse the repository at this point in the history
  • Loading branch information
oubiwann committed Dec 14, 2023
1 parent 8bdbfdd commit 3f0c17e
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 3 deletions.
9 changes: 9 additions & 0 deletions rucksack/src/command/args/dedupe.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use clap::Arg;

pub fn dd_type() -> Arg {
Arg::new("type")
.help("The type of deduplication to perform")
.short('t')
.long("type")
.env("RUXAK_DEDUPE_TYPE")
}
1 change: 1 addition & 0 deletions rucksack/src/command/args/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! # (a support module)
pub mod db;
pub mod dedupe;
pub mod record;
pub mod top;
5 changes: 3 additions & 2 deletions rucksack/src/command/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use clap::ArgMatches;

use crate::app::App;

use super::handlers::{add, backup, config, delete, export, gen, import, list, set, show};
use super::handlers::{add, backup, config, dedupe, delete, export, gen, import, list, set, show};

pub fn run(app: &App, matches: &ArgMatches) -> Result<()> {
match matches.subcommand() {
Expand All @@ -24,6 +24,8 @@ pub fn run(app: &App, matches: &ArgMatches) -> Result<()> {
Some((&_, _)) => todo!(),
None => todo!(),
},
Some(("dedupe", dedupe_matches)) => dedupe::new(dedupe_matches, app),
Some(("delete", delete_matches)) => delete::one(delete_matches, app),
Some(("export", export_matches)) => export::new(export_matches, app),
Some(("gen", gen_matches)) => gen::new(gen_matches),
Some(("import", import_matches)) => import::new(import_matches, app),
Expand All @@ -35,7 +37,6 @@ pub fn run(app: &App, matches: &ArgMatches) -> Result<()> {
Some((&_, _)) => todo!(),
None => list::all(list_matches, app),
},
Some(("delete", delete_matches)) => delete::one(delete_matches, app),
Some(("set", set_matches)) => match set_matches.subcommand() {
Some(("password", password_matches)) => set::password(password_matches, app),
Some(("status", status_matches)) => set::status(status_matches, app),
Expand Down
62 changes: 62 additions & 0 deletions rucksack/src/command/handlers/dedupe.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//! # Deduplicating Records
//!
//! To combine all separate records that have the same data, converting them
//! instead to history entries for one record:
//!
//! ```shell
//! rucksack dedupe --type exact
//! ```
//!
//! The dedupe type `exact` is the safest and thus the default type, so the above
//! may be executed more succinctly with:
//!
//! ```shell
//! rucksack dedupe
//! ```
//!
//! To combine records that differ only by password, converting them to history
//! entries of one (the oldest) record and to set the most recent (timestamp)
//! as current:
//!
//! ```shell
//! rucksack deduple --type updated
//! ```
// use anyhow::{anyhow, Result};
use anyhow::Result;
use clap::ArgMatches;

// use rucksack_db as store;
use rucksack_db::db::DB;
// use rucksack_db::records;

use crate::app::App;
// use crate::input::{query, Flag};

pub fn new(matches: &ArgMatches, app: &App) -> Result<()> {
match matches.get_one::<String>("type").map(|s| s.as_str()) {
Some("exact") => dedupe_exact(matches, &app.db)?,
Some("updated") => dedupe_passwords_updated(matches, &app.db)?,
Some("all") => dedupe_all(matches, &app.db)?,
Some("") => dedupe_exact(matches, &app.db)?,
Some(_) => todo!(),
None => dedupe_exact(matches, &app.db)?,
};
app.db.close()?;
Ok(())
}

fn dedupe_exact(_matches: &ArgMatches, _db: &DB) -> Result<(), anyhow::Error> {
log::debug!("Performing exact record deduplication ...");
Ok(())
}

fn dedupe_passwords_updated(_matches: &ArgMatches, _db: &DB) -> Result<(), anyhow::Error> {
log::debug!("Performing updated password record deduplication ...");
Ok(())
}

fn dedupe_all(matches: &ArgMatches, db: &DB) -> Result<(), anyhow::Error> {
dedupe_exact(matches, db)?;
dedupe_passwords_updated(matches, db)?;
Ok(())
}
1 change: 1 addition & 0 deletions rucksack/src/command/handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ pub mod add;
pub mod backup;
pub mod completions;
pub mod config;
pub mod dedupe;
pub mod delete;
pub mod export;
pub mod gen;
Expand Down
11 changes: 10 additions & 1 deletion rucksack/src/command/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use rucksack_db::records;

use crate::input::constant;

use super::args::{db, record, top};
use super::args::{db, dedupe, record, top};
pub use crate::command::handlers::completions::completions;
pub use crate::command::handlers::help::long_help;
pub use crate::command::handlers::version::version;
Expand Down Expand Up @@ -96,6 +96,15 @@ pub fn run() -> Command {
Command::new("re-init")
.about("Re-initialise (overwrite) the rucksack config"))
)
.subcommand(
Command::new("dedupe")
.about("Deduplication operations on rucksack records")
.arg(db::path())
.arg(db::pwd())
.arg(db::salt())
.arg(db::backup_dir())
.arg(dedupe::dd_type())
)
.subcommand(
Command::new("delete")
.about("Delete a single record")
Expand Down

0 comments on commit 3f0c17e

Please sign in to comment.