News
Introduction
Generic list/table output formatting for clap-based CLI commands, built on tabled.
Usage
Add this package to the appropriate Cargo.toml:
mfgames-cli-table = { git = "https://src.mfgames.com/mfgames-rs/mfgames-cli-table.git" }
Command Arguments
This library contains a common set of options for clap that have no short form to avoid collisions:
--markdownformats the table in Markdown--jsonformats the table in JSON--format FORMATformats the table in the given format:nonedoesn't output the data at allplaina plain format with minimal bordersmarkdownformats it as Markdownjsonformats it as a single line JSON (format withjqif you need it pretty)
The three top-level arguments are mutually exclusive and all output always goes to stdout.
Printing
To format the data, take a Vec of row data that derived Tabled (for the table formatting) and Serialize (for JSON) and pass it into print_table:
#[derive(Tabled, Serialize)]
struct Row
{
name: String,
}
fn run(command: &ListCommand)
{
let rows = vec![Row { name: "example".into() }];
print_table(rows, &command.table_options);
}
There is also a render_table which does the same but instead of printing it, it returns it as a string.