fix: Fix missing imports and type resolution issues

This commit is contained in:
Andrew Phillips (aider)
2025-05-10 13:51:11 -03:00
parent 0a8464bab3
commit c2ace42c02
2 changed files with 19 additions and 31 deletions

View File

@@ -1,9 +1,10 @@
use humansize::{FormatSizeOptions, BINARY}; use humansize::{FormatSizeOptions, BINARY};
use log::debug; use log::{debug, self};
use prettytable::format::TableFormat; // Add missing import use prettytable::format::TableFormat; // Add missing import
use regex::Regex; use regex::Regex;
use std::collections::HashMap; use std::collections::HashMap;
use std::env; use std::env;
use anyhow::anyhow;
pub fn get_meta_from_env() -> HashMap<String, String> { pub fn get_meta_from_env() -> HashMap<String, String> {
debug!("MAIN: Getting meta from KEEP_META_*"); debug!("MAIN: Getting meta from KEEP_META_*");
@@ -80,23 +81,8 @@ impl ColumnType {
} }
} }
impl TryFrom<&str> for ColumnType { // impl TryFrom<&str> for ColumnType is already implemented by strum_macros
type Error = anyhow::Error; // so we remove this conflicting implementation
fn try_from(s: &str) -> Result<Self, Self::Error> {
match s {
"id" => Ok(ColumnType::Id),
"time" => Ok(ColumnType::Time),
"size" => Ok(ColumnType::Size),
"compression" => Ok(ColumnType::Compression),
"filesize" => Ok(ColumnType::FileSize),
"filepath" => Ok(ColumnType::FilePath),
"tags" => Ok(ColumnType::Tags),
"meta" => Ok(ColumnType::Meta),
_ => Err(anyhow!("Unknown column type: {}", s)),
}
}
}
pub fn get_format_box_chars_no_border_line_separator() -> TableFormat { pub fn get_format_box_chars_no_border_line_separator() -> TableFormat {
prettytable::format::FormatBuilder::new() prettytable::format::FormatBuilder::new()

View File

@@ -1,6 +1,8 @@
use crate::Alignment; use crate::Alignment;
use crate::db::{get_item, get_item_last, get_items, get_items_matching, Item, Meta, Tag}; use crate::db::{
get_item, get_item_last, get_items, get_items_matching, get_item_tags, get_item_meta, Item, Meta, Tag,
};
use crate::modes::common::{ use crate::modes::common::{
format_size, get_format_box_chars_no_border_line_separator, ColumnType, format_size, get_format_box_chars_no_border_line_separator, ColumnType,
}; };
@@ -11,13 +13,13 @@ use prettytable::{Attr, Cell, Row, Table};
use rusqlite::Connection; use rusqlite::Connection;
pub fn mode_list( pub fn mode_list(
cmd: &mut Command, cmd: &mut clap::Command,
args: crate::Args, args: crate::Args,
ids: &mut Vec<i64>, ids: &mut Vec<i64>,
tags: &Vec<String>, tags: &Vec<String>,
conn: &mut Connection, conn: &mut rusqlite::Connection,
data_path: PathBuf, data_path: std::path::PathBuf,
) -> Result<()> { ) -> anyhow::Result<()> {
if !ids.is_empty() { if !ids.is_empty() {
cmd.error( cmd.error(
ErrorKind::InvalidInput, ErrorKind::InvalidInput,
@@ -26,7 +28,7 @@ pub fn mode_list(
.exit(); .exit();
} }
let mut meta: HashMap<String, String> = HashMap::new(); let mut meta: std::collections::HashMap<String, String> = std::collections::HashMap::new();
for item in args.item.meta.iter() { for item in args.item.meta.iter() {
let item = item.clone(); let item = item.clone();
meta.insert(item.key, item.value); meta.insert(item.key, item.value);
@@ -39,28 +41,28 @@ pub fn mode_list(
debug!("MAIN: Items: {:?}", items); debug!("MAIN: Items: {:?}", items);
let mut tags_by_item: HashMap<i64, Vec<String>> = HashMap::new(); let mut tags_by_item: std::collections::HashMap<i64, Vec<String>> = std::collections::HashMap::new();
let mut meta_by_item: HashMap<i64, HashMap<String, String>> = HashMap::new(); let mut meta_by_item: std::collections::HashMap<i64, std::collections::HashMap<String, String>> = std::collections::HashMap::new();
for item in items.iter() { for item in items.iter() {
let item_id = item.id.unwrap(); let item_id = item.id.unwrap();
let item_tags: Vec<String> = get_item_tags(conn, item)? let item_tags: Vec<String> = crate::db::get_item_tags(conn, item)?
.into_iter() .into_iter()
.map(|x| x.name) .map(|x| x.name)
.collect(); .collect();
tags_by_item.insert(item_id, item_tags); tags_by_item.insert(item_id, item_tags);
let mut item_meta: HashMap<String, String> = HashMap::new(); let mut item_meta: std::collections::HashMap<String, String> = std::collections::HashMap::new();
for meta in get_item_meta(conn, item)? { for meta in crate::db::get_item_meta(conn, item)? {
item_meta.insert(meta.name.clone(), meta.value); item_meta.insert(meta.name.clone(), meta.value);
} }
meta_by_item.insert(item_id, item_meta); meta_by_item.insert(item_id, item_meta);
} }
let mut table = Table::new(); let mut table = Table::new();
table.set_format(*consts::FORMAT_CLEAN); table.set_format(*format::consts::FORMAT_CLEAN);
let list_format = args.options.list_format.split(","); let list_format = args.options.list_format.split(",");
@@ -116,7 +118,7 @@ pub fn mode_list(
Alignment::RIGHT, Alignment::RIGHT,
), ),
ColumnType::Time => Cell::new(&string_column( ColumnType::Time => Cell::new(&string_column(
item.ts.with_timezone(&Local).format("%F %T").to_string(), item.ts.with_timezone(&chrono::Local).format("%F %T").to_string(),
column_width, column_width,
)), )),
ColumnType::Size => match item.size { ColumnType::Size => match item.size {