use prettytable for tabular outputs

This commit is contained in:
Dustin J. Mitchell
2020-11-23 21:58:45 -05:00
parent f7f5c379ea
commit f31a96176d
6 changed files with 180 additions and 2 deletions

View File

@@ -1,5 +1,7 @@
use crate::table;
use clap::{App, ArgMatches, SubCommand as ClapSubCommand};
use failure::Fallible;
use prettytable::{cell, row, Table};
use crate::cmd::{ArgMatchResult, CommandInvocation};
@@ -21,9 +23,13 @@ define_subcommand! {
subcommand_invocation! {
fn run(&self, command: &CommandInvocation) -> Fallible<()> {
let mut t = Table::new();
t.set_format(table::format());
t.set_titles(row![b->"uuid", b->"description"]);
for (uuid, task) in command.get_replica().all_tasks().unwrap() {
println!("{} - {:?}", uuid, task);
t.add_row(row![uuid, task.get_description()]);
}
t.printstd();
Ok(())
}
}

View File

@@ -1,5 +1,7 @@
use crate::table;
use clap::{App, ArgMatches, SubCommand as ClapSubCommand};
use failure::Fallible;
use prettytable::{cell, row, Table};
use crate::cmd::{ArgMatchResult, CommandInvocation};
@@ -24,11 +26,15 @@ define_subcommand! {
subcommand_invocation! {
fn run(&self, command: &CommandInvocation) -> Fallible<()> {
let working_set = command.get_replica().working_set().unwrap();
let mut t = Table::new();
t.set_format(table::format());
t.set_titles(row![b->"id", b->"description"]);
for i in 1..working_set.len() {
if let Some(ref task) = working_set[i] {
println!("{}: {} - {:?}", i, task.get_uuid(), task);
t.add_row(row![i, task.get_description()]);
}
}
t.printstd();
Ok(())
}
}

View File

@@ -3,6 +3,8 @@ use failure::Fallible;
use std::ffi::OsString;
mod cmd;
mod table;
use cmd::ArgMatchResult;
pub use cmd::CommandInvocation;

8
cli/src/table.rs Normal file
View File

@@ -0,0 +1,8 @@
use prettytable::format;
pub(crate) fn format() -> format::TableFormat {
format::FormatBuilder::new()
.column_separator(' ')
.borders(' ')
.build()
}