2021-09-10 17:33:42 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.CommandLine;
|
|
|
|
using System.CommandLine.Invocation;
|
|
|
|
using System.Data;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
using MfGames.ToolBuilder.Tables;
|
|
|
|
|
|
|
|
namespace SampleTool
|
|
|
|
{
|
2022-03-31 05:17:04 +00:00
|
|
|
public class TableCommand : Command, ICommandHandler
|
2021-09-10 17:33:42 +00:00
|
|
|
{
|
|
|
|
private readonly DataTable table;
|
|
|
|
|
|
|
|
private readonly TableToolService tableService;
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
2022-03-31 05:17:04 +00:00
|
|
|
public TableCommand(TableToolService.Factory tableService)
|
2021-09-10 17:33:42 +00:00
|
|
|
: base("table", "Display a table.")
|
|
|
|
{
|
|
|
|
// Create the table structure.
|
|
|
|
this.table = new DataTable();
|
|
|
|
this.table.Columns.Add("DefaultString", typeof(string));
|
|
|
|
this.table.Columns.Add("DefaultInt32", typeof(int));
|
|
|
|
this.table.Columns.Add("HiddenString", typeof(string));
|
|
|
|
|
|
|
|
// Create the table service for formatting and displaying results.
|
|
|
|
this.tableService = tableService(
|
|
|
|
this,
|
|
|
|
this.table,
|
|
|
|
new List<string>
|
|
|
|
{
|
|
|
|
"DefaultString",
|
|
|
|
"DefaultInt32",
|
|
|
|
});
|
2022-03-31 05:17:04 +00:00
|
|
|
|
2021-09-10 17:33:42 +00:00
|
|
|
// This class handles the command.
|
|
|
|
this.Handler = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
public Task<int> InvokeAsync(InvocationContext context)
|
|
|
|
{
|
|
|
|
this.table.Rows.Add("Row 1", 1, "Hidden 1");
|
|
|
|
this.table.Rows.Add("Row 2", 10, "Hidden 2");
|
|
|
|
this.table.Rows.Add("Row 3", 100, "Hidden 3");
|
|
|
|
|
|
|
|
this.tableService.Write(context);
|
|
|
|
|
|
|
|
return Task.FromResult(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|