fix: Use prettytable for detailed database output

pull/24376/head
Carol (Nichols || Goulding) 2021-09-17 15:55:37 -04:00
parent 6520985b5d
commit ac9c25d33c
2 changed files with 23 additions and 8 deletions

View File

@ -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"))

View File

@ -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]