diff --git a/src/modes/common.rs b/src/modes/common.rs index 6af5bfb..9e6e227 100644 --- a/src/modes/common.rs +++ b/src/modes/common.rs @@ -1,9 +1,10 @@ use humansize::{FormatSizeOptions, BINARY}; -use log::debug; +use log::{debug, self}; use prettytable::format::TableFormat; // Add missing import use regex::Regex; use std::collections::HashMap; use std::env; +use anyhow::anyhow; pub fn get_meta_from_env() -> HashMap { debug!("MAIN: Getting meta from KEEP_META_*"); @@ -80,23 +81,8 @@ impl ColumnType { } } -impl TryFrom<&str> for ColumnType { - type Error = anyhow::Error; - - fn try_from(s: &str) -> Result { - 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)), - } - } -} +// impl TryFrom<&str> for ColumnType is already implemented by strum_macros +// so we remove this conflicting implementation pub fn get_format_box_chars_no_border_line_separator() -> TableFormat { prettytable::format::FormatBuilder::new() diff --git a/src/modes/list.rs b/src/modes/list.rs index ab3eac9..d2d4b07 100644 --- a/src/modes/list.rs +++ b/src/modes/list.rs @@ -1,6 +1,8 @@ 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::{ format_size, get_format_box_chars_no_border_line_separator, ColumnType, }; @@ -11,13 +13,13 @@ use prettytable::{Attr, Cell, Row, Table}; use rusqlite::Connection; pub fn mode_list( - cmd: &mut Command, + cmd: &mut clap::Command, args: crate::Args, ids: &mut Vec, tags: &Vec, - conn: &mut Connection, - data_path: PathBuf, -) -> Result<()> { + conn: &mut rusqlite::Connection, + data_path: std::path::PathBuf, +) -> anyhow::Result<()> { if !ids.is_empty() { cmd.error( ErrorKind::InvalidInput, @@ -26,7 +28,7 @@ pub fn mode_list( .exit(); } - let mut meta: HashMap = HashMap::new(); + let mut meta: std::collections::HashMap = std::collections::HashMap::new(); for item in args.item.meta.iter() { let item = item.clone(); meta.insert(item.key, item.value); @@ -39,28 +41,28 @@ pub fn mode_list( debug!("MAIN: Items: {:?}", items); - let mut tags_by_item: HashMap> = HashMap::new(); - let mut meta_by_item: HashMap> = HashMap::new(); + let mut tags_by_item: std::collections::HashMap> = std::collections::HashMap::new(); + let mut meta_by_item: std::collections::HashMap> = std::collections::HashMap::new(); for item in items.iter() { let item_id = item.id.unwrap(); - let item_tags: Vec = get_item_tags(conn, item)? + let item_tags: Vec = crate::db::get_item_tags(conn, item)? .into_iter() .map(|x| x.name) .collect(); tags_by_item.insert(item_id, item_tags); - let mut item_meta: HashMap = HashMap::new(); + let mut item_meta: std::collections::HashMap = 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); } meta_by_item.insert(item_id, item_meta); } 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(","); @@ -116,7 +118,7 @@ pub fn mode_list( Alignment::RIGHT, ), 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, )), ColumnType::Size => match item.size {