use prettytable for tabular outputs
This commit is contained in:
@@ -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(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
8
cli/src/table.rs
Normal file
@@ -0,0 +1,8 @@
|
||||
use prettytable::format;
|
||||
|
||||
pub(crate) fn format() -> format::TableFormat {
|
||||
format::FormatBuilder::new()
|
||||
.column_separator(' ')
|
||||
.borders(' ')
|
||||
.build()
|
||||
}
|
||||
Reference in New Issue
Block a user