From e18a928db5916fce43c35dff585072dace0da7e0 Mon Sep 17 00:00:00 2001 From: Justin Wernick Date: Mon, 3 Jul 2023 21:54:21 +0200 Subject: Added a new "--verbose" option to the list command --- src/lib.rs | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index 32d5770..809c62d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,6 +3,7 @@ mod parser; pub mod user_info; use comfy_table::Table; +use humansize::{format_size, BINARY}; use parser::*; use rustyline::error::ReadlineError; use std::{io, ops::ControlFlow}; @@ -16,12 +17,24 @@ pub fn run_command(user_input: &str) -> Result, ShackleError Ok(ShackleCommand::Exit) => { return Ok(ControlFlow::Break(())); } - Ok(ShackleCommand::List) => { + Ok(ShackleCommand::List(ListArgs { verbose })) => { let mut table = Table::new(); - table.set_header(vec!["path", "description"]); - let listing = git::list()?; - for meta in listing { - table.add_row(vec![meta.path.display().to_string(), meta.description]); + if !verbose { + table.set_header(vec!["path", "description"]); + let listing = git::list()?; + for meta in listing { + table.add_row(vec![meta.path.display().to_string(), meta.description]); + } + } else { + table.set_header(vec!["path", "description", "size"]); + let listing = git::list_verbose()?; + for meta in listing { + table.add_row(vec![ + meta.path.display().to_string(), + meta.description, + format_size(meta.size, BINARY), + ]); + } } println!("{table}"); -- cgit v1.2.3