pub mod job;
pub mod keyring;
use crate::cli::Commands;
pub const FAILURE_EXIT_CODE: i32 = 1;
pub(crate) fn fail(message: impl std::fmt::Display) -> i32 {
tracing::error!(error = %message, "job failed");
eprintln!("Error: {message}");
FAILURE_EXIT_CODE
}
pub fn dispatch(command: Commands) -> i32 {
match command {
Commands::Keyring(args) => crate::commands::keyring::commands::dispatch(args.command),
Commands::Job(args) => crate::commands::job::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));
}
}