refactor: move list mode handling to modes/list.rs
This commit is contained in:
committed by
Andrew Phillips (aider)
parent
5c76d4c15c
commit
d9defdec45
@@ -3,11 +3,11 @@ use crate::Alignment;
|
||||
use crate::db::{get_items, get_items_matching};
|
||||
use crate::modes::common::ColumnType;
|
||||
use crate::modes::common::{size_column, string_column};
|
||||
use anyhow::anyhow;
|
||||
use log::debug;
|
||||
use prettytable::color;
|
||||
use prettytable::row;
|
||||
use prettytable::{Attr, Cell, Row, Table};
|
||||
use log::debug;
|
||||
use anyhow::anyhow;
|
||||
|
||||
pub fn mode_list(
|
||||
cmd: &mut clap::Command,
|
||||
@@ -38,8 +38,12 @@ pub fn mode_list(
|
||||
|
||||
debug!("MAIN: Items: {:?}", items);
|
||||
|
||||
let mut tags_by_item: std::collections::HashMap<i64, Vec<String>> = std::collections::HashMap::new();
|
||||
let mut meta_by_item: std::collections::HashMap<i64, std::collections::HashMap<String, String>> = std::collections::HashMap::new();
|
||||
let mut tags_by_item: std::collections::HashMap<i64, Vec<String>> =
|
||||
std::collections::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() {
|
||||
let item_id = item.id.unwrap();
|
||||
@@ -50,7 +54,8 @@ pub fn mode_list(
|
||||
.collect();
|
||||
tags_by_item.insert(item_id, item_tags);
|
||||
|
||||
let mut item_meta: std::collections::HashMap<String, String> = std::collections::HashMap::new();
|
||||
let mut item_meta: std::collections::HashMap<String, String> =
|
||||
std::collections::HashMap::new();
|
||||
|
||||
for meta in crate::db::get_item_meta(conn, item)? {
|
||||
item_meta.insert(meta.name.clone(), meta.value);
|
||||
@@ -68,9 +73,8 @@ pub fn mode_list(
|
||||
for column in list_format.clone() {
|
||||
let mut column_format = column.split(":").into_iter();
|
||||
let column_name = column_format.next().expect("Unable to parse column name");
|
||||
let column_type = ColumnType::from_str(column_name).map_err(|_| {
|
||||
anyhow!("Unknown column {:?}", column_name)
|
||||
})?;
|
||||
let column_type = ColumnType::from_str(column_name)
|
||||
.map_err(|_| anyhow!("Unknown column {:?}", column_name))?;
|
||||
|
||||
if column_type == ColumnType::Meta {
|
||||
let meta_name = column_format
|
||||
@@ -115,7 +119,10 @@ pub fn mode_list(
|
||||
Alignment::RIGHT,
|
||||
),
|
||||
ColumnType::Time => Cell::new(&string_column(
|
||||
item.ts.with_timezone(&chrono::Local).format("%F %T").to_string(),
|
||||
item.ts
|
||||
.with_timezone(&chrono::Local)
|
||||
.format("%F %T")
|
||||
.to_string(),
|
||||
column_width,
|
||||
)),
|
||||
ColumnType::Size => match item.size {
|
||||
|
||||
@@ -5,9 +5,9 @@ use std::path::PathBuf;
|
||||
use strum::IntoEnumIterator;
|
||||
|
||||
use crate::compression::default_type;
|
||||
use crate::compression::program::CompressionEngineProgram;
|
||||
use crate::compression::CompressionType;
|
||||
use crate::compression::COMPRESSION_PROGRAMS;
|
||||
use crate::compression::program::CompressionEngineProgram;
|
||||
use std::str::FromStr;
|
||||
|
||||
use crate::FORMAT_BOX_CHARS_NO_BORDER_LINE_SEPARATOR;
|
||||
|
||||
Reference in New Issue
Block a user