This commit is contained in:
Andrew Phillips
2026-02-19 13:57:39 -04:00
parent a72395fe83
commit fdeb5f7951
82 changed files with 2756 additions and 2018 deletions

View File

@@ -1,15 +1,15 @@
use crate::config;
use crate::modes::common::{OutputFormat, format_size};
use crate::services::types::ItemWithMeta;
use crate::modes::common::{format_size, OutputFormat};
use anyhow::{anyhow, Result};
use serde::{Deserialize, Serialize};
use anyhow::{Result, anyhow};
use clap::Command;
use clap::error::ErrorKind;
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
use crate::services::item_service::ItemService;
use chrono::prelude::*;
use comfy_table::{Cell, Attribute};
use comfy_table::{Attribute, Cell};
/// Displays detailed information about an item or the last item if no ID/tags specified.
///
@@ -42,16 +42,24 @@ use comfy_table::{Cell, Attribute};
pub fn mode_info(
cmd: &mut Command,
settings: &config::Settings,
ids: &mut Vec<i64>,
tags: &mut Vec<String>,
ids: &mut [i64],
tags: &mut [String],
conn: &mut rusqlite::Connection,
data_path: PathBuf,
) -> Result<()> {
// For --info, we can use either IDs or tags, but not both
if !ids.is_empty() && !tags.is_empty() {
cmd.error(ErrorKind::InvalidValue, "Both ID and tags given, you must supply either IDs or tags when using --info").exit();
cmd.error(
ErrorKind::InvalidValue,
"Both ID and tags given, you must supply either IDs or tags when using --info",
)
.exit();
} else if ids.len() > 1 {
cmd.error(ErrorKind::InvalidValue, "More than one ID given, you must supply exactly one ID when using --info").exit();
cmd.error(
ErrorKind::InvalidValue,
"More than one ID given, you must supply exactly one ID when using --info",
)
.exit();
}
// If both are empty, find_item will find the last item
@@ -139,7 +147,7 @@ fn show_item(
// Add all the rows
table.add_row(vec![
Cell::new("ID").add_attribute(Attribute::Bold),
Cell::new(&item_id.to_string()),
Cell::new(item_id.to_string()),
]);
let timestamp_str = item.ts.with_timezone(&Local).format("%F %T %Z").to_string();
@@ -150,7 +158,10 @@ fn show_item(
let mut item_path_buf = data_path.clone();
item_path_buf.push(item.id.unwrap().to_string());
let path_str = item_path_buf.to_str().expect("Unable to get item path").to_string();
let path_str = item_path_buf
.to_str()
.expect("Unable to get item path")
.to_string();
table.add_row(vec![
Cell::new("Path").add_attribute(Attribute::Bold),
Cell::new(&path_str),
@@ -194,7 +205,10 @@ fn show_item(
]);
}
println!("{}", crate::modes::common::trim_lines_end(&table.trim_fmt()));
println!(
"{}",
crate::modes::common::trim_lines_end(&table.trim_fmt())
);
Ok(())
}