-
-
Notifications
You must be signed in to change notification settings - Fork 61
Integrating with ConsoleTables
Alexey Golub edited this page Nov 3, 2020
·
1 revision
ConsoleTables is a utility library for rendering tables via console output.
To integrate it with CliFx:
-
Install ConsoleTables NuGet package
-
Create an instance of
ConsoleTable
bound to the console instance provided by CliFx command:
[Command]
public class TestCommand : ICommand
{
public ValueTask ExecuteAsync(IConsole console)
{
var table = new ConsoleTable(new ConsoleTableOptions
{
OutputTo = console.Output
});
table
.AddRow(1, 2, 3)
.AddRow("foo", "bar", "baz");
table.Write();
// ...
}
}
Alternatively, use the fluent API and call the Configure()
method:
[Command]
public class TestCommand : ICommand
{
public ValueTask ExecuteAsync(IConsole console)
{
var rows = Enumerable.Repeat(new Something(), 10);
ConsoleTable
.From<Something>(rows)
.Configure(o => o.OutputTo = console.Output)
.Write();
// ...
}
}