modularize codebase

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I6a6a69648ea836bfeb539450db14a666c623412e
This commit is contained in:
raf 2025-08-12 13:56:31 +03:00
commit b0820a1940
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
10 changed files with 445 additions and 252 deletions

12
src/commands/decode.rs Normal file
View file

@ -0,0 +1,12 @@
use crate::db::{ClipboardDb, SledClipboardDb};
use std::io::{Read, Write};
pub trait DecodeCommand {
fn decode(&self, in_: impl Read, out: impl Write, input: Option<String>);
}
impl DecodeCommand for SledClipboardDb {
fn decode(&self, in_: impl Read, out: impl Write, input: Option<String>) {
self.decode_entry(in_, out, input);
}
}

12
src/commands/delete.rs Normal file
View file

@ -0,0 +1,12 @@
use crate::db::{ClipboardDb, SledClipboardDb};
use std::io::Read;
pub trait DeleteCommand {
fn delete(&self, input: impl Read);
}
impl DeleteCommand for SledClipboardDb {
fn delete(&self, input: impl Read) {
self.delete_entries(input);
}
}

12
src/commands/list.rs Normal file
View file

@ -0,0 +1,12 @@
use crate::db::{ClipboardDb, SledClipboardDb};
use std::io::Write;
pub trait ListCommand {
fn list(&self, out: impl Write, preview_width: u32);
}
impl ListCommand for SledClipboardDb {
fn list(&self, out: impl Write, preview_width: u32) {
self.list_entries(out, preview_width);
}
}

6
src/commands/mod.rs Normal file
View file

@ -0,0 +1,6 @@
pub mod decode;
pub mod delete;
pub mod list;
pub mod query;
pub mod store;
pub mod wipe;

11
src/commands/query.rs Normal file
View file

@ -0,0 +1,11 @@
use crate::db::{ClipboardDb, SledClipboardDb};
pub trait QueryCommand {
fn query_delete(&self, query: &str);
}
impl QueryCommand for SledClipboardDb {
fn query_delete(&self, query: &str) {
<SledClipboardDb as ClipboardDb>::delete_query(self, query);
}
}

31
src/commands/store.rs Normal file
View file

@ -0,0 +1,31 @@
use crate::db::{ClipboardDb, SledClipboardDb};
use std::io::Read;
pub trait StoreCommand {
fn store(
&self,
input: impl Read,
max_dedupe_search: u64,
max_items: u64,
state: Option<String>,
);
}
impl StoreCommand for SledClipboardDb {
fn store(
&self,
input: impl Read,
max_dedupe_search: u64,
max_items: u64,
state: Option<String>,
) {
match state.as_deref() {
Some("sensitive") | Some("clear") => {
self.delete_last();
}
_ => {
self.store_entry(input, max_dedupe_search, max_items);
}
}
}
}

11
src/commands/wipe.rs Normal file
View file

@ -0,0 +1,11 @@
use crate::db::{ClipboardDb, SledClipboardDb};
pub trait WipeCommand {
fn wipe(&self);
}
impl WipeCommand for SledClipboardDb {
fn wipe(&self) {
self.wipe_db();
}
}