diff --git a/src/commands/database.rs b/src/commands/database.rs index a9161484a0..36d961585f 100644 --- a/src/commands/database.rs +++ b/src/commands/database.rs @@ -11,6 +11,7 @@ use influxdb_iox_client::{ }, write::{self, WriteError}, }; +use prettytable::{format, Cell, Row, Table}; use std::{ convert::TryInto, fs::File, io::Read, num::NonZeroU64, path::PathBuf, str::FromStr, time::Duration, @@ -269,8 +270,15 @@ pub async fn command(connection: Connection, config: Config) -> Result<()> { } else { client.list_detailed_databases().await? }; - println!("Deleted at | Generation ID | Name"); - println!("---------------------------------+---------------+--------"); + + let mut table = Table::new(); + table.set_format(*format::consts::FORMAT_NO_LINESEP_WITH_TITLE); + table.set_titles(Row::new(vec![ + Cell::new("Deleted at"), + Cell::new("Generation ID"), + Cell::new("Name"), + ])); + for database in databases { let deleted_at = database .deleted_at @@ -279,11 +287,14 @@ pub async fn command(connection: Connection, config: Config) -> Result<()> { dt.ok().map(|d| d.to_string()) }) .unwrap_or_else(String::new); - println!( - "{:<34}{:<16}{}", - deleted_at, database.generation_id, database.db_name, - ); + table.add_row(Row::new(vec![ + Cell::new(&deleted_at), + Cell::new(&database.generation_id.to_string()), + Cell::new(&database.db_name), + ])); } + + print!("{}", table); } else { let names = client.list_database_names().await?; println!("{}", names.join("\n")) diff --git a/tests/end_to_end_cases/management_cli.rs b/tests/end_to_end_cases/management_cli.rs index 1e8840350c..72671eefe2 100644 --- a/tests/end_to_end_cases/management_cli.rs +++ b/tests/end_to_end_cases/management_cli.rs @@ -187,14 +187,18 @@ const DELETED_DB_DATETIME: &str = r#"[\d-]+\s[\d:\.]+\s[A-Z]+"#; fn deleted_db_match(db: &str, generation_id: usize) -> predicates::str::RegexPredicate { predicate::str::is_match(format!( - r#"(?m)^{}\s+{}\s+{}$"#, + r#"(?m)^\|\s+{}\s+\|\s+{}\s+\|\s+{}\s+\|$"#, DELETED_DB_DATETIME, generation_id, db )) .unwrap() } fn active_db_match(db: &str, generation_id: usize) -> predicates::str::RegexPredicate { - predicate::str::is_match(format!(r#"(?m)^\s+{}\s+{}$"#, generation_id, db)).unwrap() + predicate::str::is_match(format!( + r#"(?m)^\|\s+\|\s+{}\s+\|\s+{}\s+\|$"#, + generation_id, db + )) + .unwrap() } #[tokio::test]