use crate::cli::Commands;
pub const FAILURE_EXIT_CODE: i32 = 1;
pub fn dispatch(command: Commands) -> i32 {
match command {
Commands::Email(args) => crate::email::commands::dispatch(args.command),
Commands::Dataops(args) => crate::dataops::commands::dispatch(args.command),
}
}
pub fn print_table(headers: &[&str], rows: &[Vec<String>]) {
let mut widths: Vec<usize> = headers.iter().map(|h| h.len()).collect();
for row in rows {
for (i, cell) in row.iter().enumerate() {
widths[i] = widths[i].max(cell.len());
}
}
let format_row = |cells: &[String]| -> String {
cells
.iter()
.enumerate()
.map(|(i, cell)| format!("{:width$}", cell, width = widths[i]))
.collect::<Vec<_>>()
.join(" ")
.trim_end()
.to_string()
};
let header_row: Vec<String> = headers.iter().map(|h| h.to_string()).collect();
println!("{}", format_row(&header_row));
for row in rows {
println!("{}", format_row(row));
}
}