1pub mod json;
2pub mod table;
3
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub enum OutputFormat {
6 Table,
7 Json,
8}
9
10pub trait Tabular {
11 fn headers() -> Vec<&'static str>;
12 fn row(&self) -> Vec<String>;
13}
14
15pub fn print_list<T: serde::Serialize + Tabular>(items: &[T], format: OutputFormat) {
16 match format {
17 OutputFormat::Table => table::print_table::<T>(items),
18 OutputFormat::Json => json::print_json(items),
19 }
20}
21
22pub fn print_detail<T: serde::Serialize>(
23 item: &T,
24 format: OutputFormat,
25 fields: &[(&str, String)],
26) {
27 match format {
28 OutputFormat::Table => table::print_key_value(fields),
29 OutputFormat::Json => json::print_json(item),
30 }
31}
32
33pub fn print_message(msg: &str) {
34 println!("{msg}");
35}
36
37pub fn print_pagination(current: u32, total_pages: u32, total_items: u32, format: OutputFormat) {
38 if format == OutputFormat::Json {
39 return;
40 }
41 if total_pages > 1 {
42 println!("Page {current} of {total_pages} ({total_items} total)");
43 }
44}