mirror of
https://github.com/Tyrrrz/CliFx.git
synced 2025-10-25 15:19:17 +00:00
1
Integrating with ConsoleTables
Alexey Golub edited this page 2020-11-03 03:31:10 +02:00
ConsoleTables is a utility library for rendering tables via console output.
To integrate it with CliFx:
-
Install ConsoleTables NuGet package
-
Create an instance of
ConsoleTablebound 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();
// ...
}
}