From 33fa31bbb6a2671363c79792535976586e802e78 Mon Sep 17 00:00:00 2001 From: "Andrew Phillips (aider)" Date: Sat, 10 May 2025 13:41:48 -0300 Subject: [PATCH] feat: add ColumnType as_str method and improve error handling --- src/modes/common.rs | 16 ++++++++++++++++ src/modes/list.rs | 5 +++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/modes/common.rs b/src/modes/common.rs index 3fc5798..0da264f 100644 --- a/src/modes/common.rs +++ b/src/modes/common.rs @@ -59,6 +59,22 @@ pub enum ColumnType { Meta, } +impl ColumnType { + /// Returns the human-readable string representation of the column type + pub fn as_str(&self) -> &str { + match self { + ColumnType::Id => "id", + ColumnType::Time => "time", + ColumnType::Size => "size", + ColumnType::Compression => "compression", + ColumnType::FileSize => "filesize", + ColumnType::FilePath => "filepath", + ColumnType::Tags => "tags", + ColumnType::Meta => "meta", + } + } +} + pub fn get_format_box_chars_no_border_line_separator() -> TableFormat { prettytable::format::FormatBuilder::new() .column_separator('│') diff --git a/src/modes/list.rs b/src/modes/list.rs index 858341e..ab3eac9 100644 --- a/src/modes/list.rs +++ b/src/modes/list.rs @@ -69,8 +69,9 @@ 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) - .expect(format!("Unknown column {:?}", column_name).as_str()); + 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