Ugh
This commit is contained in:
@@ -1,19 +1,27 @@
|
||||
use crate::config;
|
||||
use crate::services::item_service::ItemService;
|
||||
/// Diff mode implementation.
|
||||
///
|
||||
/// This module provides functionality for comparing two items and displaying their
|
||||
/// differences using external diff tools.
|
||||
use anyhow::{Context, Result};
|
||||
use clap::Command;
|
||||
use crate::config;
|
||||
use crate::services::item_service::ItemService;
|
||||
use log::debug;
|
||||
|
||||
fn validate_diff_args(_cmd: &mut Command, ids: &Vec<i64>, tags: &Vec<String>) -> anyhow::Result<()> {
|
||||
fn validate_diff_args(
|
||||
_cmd: &mut Command,
|
||||
ids: &Vec<i64>,
|
||||
tags: &Vec<String>,
|
||||
) -> anyhow::Result<()> {
|
||||
if !tags.is_empty() {
|
||||
return Err(anyhow::anyhow!("Tags are not supported with --diff. Please provide exactly two IDs."));
|
||||
return Err(anyhow::anyhow!(
|
||||
"Tags are not supported with --diff. Please provide exactly two IDs."
|
||||
));
|
||||
}
|
||||
if ids.len() != 2 {
|
||||
return Err(anyhow::anyhow!("You must supply exactly two IDs when using --diff."));
|
||||
return Err(anyhow::anyhow!(
|
||||
"You must supply exactly two IDs when using --diff."
|
||||
));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -34,9 +42,12 @@ fn validate_diff_args(_cmd: &mut Command, ids: &Vec<i64>, tags: &Vec<String>) ->
|
||||
/// * `Result<(ItemWithMeta, ItemWithMeta)>` - Tuple of items with metadata or error.
|
||||
fn fetch_and_validate_items(
|
||||
conn: &mut rusqlite::Connection,
|
||||
ids: &Vec<i64>,
|
||||
ids: &[i64],
|
||||
item_service: &ItemService,
|
||||
) -> Result<(crate::services::types::ItemWithMeta, crate::services::types::ItemWithMeta)> {
|
||||
) -> Result<(
|
||||
crate::services::types::ItemWithMeta,
|
||||
crate::services::types::ItemWithMeta,
|
||||
)> {
|
||||
// Fetch items using the service, which handles validation
|
||||
let item_a = item_service
|
||||
.get_item(conn, ids[0])
|
||||
@@ -69,12 +80,15 @@ fn setup_diff_paths_and_compression(
|
||||
item_service: &ItemService,
|
||||
item_a: &crate::services::types::ItemWithMeta,
|
||||
item_b: &crate::services::types::ItemWithMeta,
|
||||
) -> Result<(
|
||||
std::path::PathBuf,
|
||||
std::path::PathBuf,
|
||||
)> {
|
||||
let item_a_id = item_a.item.id.ok_or_else(|| anyhow::anyhow!("Item A missing ID"))?;
|
||||
let item_b_id = item_b.item.id.ok_or_else(|| anyhow::anyhow!("Item B missing ID"))?;
|
||||
) -> Result<(std::path::PathBuf, std::path::PathBuf)> {
|
||||
let item_a_id = item_a
|
||||
.item
|
||||
.id
|
||||
.ok_or_else(|| anyhow::anyhow!("Item A missing ID"))?;
|
||||
let item_b_id = item_b
|
||||
.item
|
||||
.id
|
||||
.ok_or_else(|| anyhow::anyhow!("Item B missing ID"))?;
|
||||
|
||||
// Use the service's data path to construct proper file paths
|
||||
let data_path = item_service.get_data_path();
|
||||
|
||||
Reference in New Issue
Block a user