Skip to content

Commit a23f372

Browse files
committed
Got rid of Spectre.Console dependency in QueueAction
1 parent 6e7b3eb commit a23f372

2 files changed

Lines changed: 44 additions & 32 deletions

File tree

servicebus-cli/Services/ConsoleService.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public interface IConsoleService
1717
Task<string> PromptForAction<ActionType>();
1818
Task<string> PromptSelection(string title, IEnumerable<string> choices, bool enableSearch = false);
1919
Task<string> PromptFreeText(string title, bool allowEmpty = false);
20+
void WriteTable(List<string> headers, List<List<string>> rows);
2021
Task<T> ProcessWorkloadWithSpinner<T>(string message, Func<Task<T>> func);
2122
Task ProcessWorkloadWithStatusUpdates<TItem, TCollection>(
2223
string taskDescriptionCurrentTense,
@@ -82,6 +83,21 @@ public Task<string> PromptFreeText(string title, bool allowEmpty = false)
8283
return AnsiConsole.PromptAsync(new TextPrompt<string>(title));
8384
}
8485

86+
public void WriteTable(List<string> headers, List<List<string>> rows)
87+
{
88+
//TODO: Make sure columns and rows match
89+
90+
var table = new Table();
91+
92+
foreach (var header in headers)
93+
table.AddColumn(header);
94+
95+
foreach (var row in rows)
96+
table.AddRow(row.ToArray());
97+
98+
AnsiConsole.Write(table);
99+
}
100+
85101
public Task<T> ProcessWorkloadWithSpinner<T>(string message, Func<Task<T>> func)
86102
{
87103
return AnsiConsole.Status()

servicebus-cli/Subjects/Queue/Actions/QueueActions.cs

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using servicebus_cli.Services;
2-
using Spectre.Console;
32

43
namespace servicebus_cli.Subjects.Queue.Actions;
54

@@ -51,41 +50,38 @@ public async Task List(List<string> args)
5150
break;
5251
}
5352

54-
//TODO: Wrap this inside ConsoleService
53+
var queueInfoWorkload = async () =>
54+
{
55+
return await _serviceBusService.GetInformationAboutAllQueues(fullyQualifiedNamespace, filter).ConfigureAwait(false);
56+
};
5557

56-
var table = await AnsiConsole.Status()
57-
.StartAsync($"Listing queues on {fullyQualifiedNamespace}...", async ctx =>
58-
{
59-
ctx.Spinner(Spinner.Known.Dots);
60-
ctx.SpinnerStyle(Style.Parse("yellow"));
61-
62-
var queuesWithInformation = await _serviceBusService.GetInformationAboutAllQueues(fullyQualifiedNamespace, filter).ConfigureAwait(false);
63-
64-
ctx.Status("Building table...");
65-
66-
var resultTable = new Table();
67-
resultTable.AddColumn("📮 [bold]Queue Name[/]");
68-
resultTable.AddColumn("[green]Active[/]");
69-
resultTable.AddColumn("[red]Dead Letter[/]");
70-
resultTable.AddColumn("[blue]Scheduled[/]");
58+
var queuesWithInformation = await _consoleService.ProcessWorkloadWithSpinner(
59+
$"Listing queues on {fullyQualifiedNamespace}...",
60+
queueInfoWorkload);
7161

72-
foreach (var queueInfo in queuesWithInformation)
73-
{
74-
var activeMessageCount = queueInfo.QueueRuntimeProperties.ActiveMessageCount;
75-
var deadLetterMessageCount = queueInfo.QueueRuntimeProperties.DeadLetterMessageCount;
76-
var scheduledMessageCount = queueInfo.QueueRuntimeProperties.ScheduledMessageCount;
62+
var headers = new List<string> {
63+
"📮 [bold]Queue Name[/]",
64+
"[green]Active[/]",
65+
"[red]Dead Letter[/]",
66+
"[blue]Scheduled[/]"
67+
};
7768

78-
resultTable.AddRow(
79-
queueInfo.QueueProperties.Name,
80-
$"[green]{activeMessageCount}[/]",
81-
$"[red]{deadLetterMessageCount}[/]",
82-
$"[blue]{scheduledMessageCount}[/]"
83-
);
84-
}
85-
86-
return resultTable;
69+
var rows = new List<List<string>>();
70+
71+
foreach (var queueInfo in queuesWithInformation)
72+
{
73+
var activeMessageCount = queueInfo.QueueRuntimeProperties.ActiveMessageCount;
74+
var deadLetterMessageCount = queueInfo.QueueRuntimeProperties.DeadLetterMessageCount;
75+
var scheduledMessageCount = queueInfo.QueueRuntimeProperties.ScheduledMessageCount;
76+
77+
rows.Add(new List<string> {
78+
queueInfo.QueueProperties.Name,
79+
$"[green]{activeMessageCount}[/]",
80+
$"[red]{deadLetterMessageCount}[/]",
81+
$"[blue]{scheduledMessageCount}[/]"
8782
});
83+
}
8884

89-
AnsiConsole.Write(table);
85+
_consoleService.WriteTable(headers, rows);
9086
}
9187
}

0 commit comments

Comments
 (0)