-
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathPrintEnvironmentVariablesModule.cs
More file actions
36 lines (29 loc) · 1.21 KB
/
PrintEnvironmentVariablesModule.cs
File metadata and controls
36 lines (29 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using ModularPipelines;
using ModularPipelines.Context;
using ModularPipelines.Modules;
using Spectre.Console;
namespace ModularPipelines.Build.Modules;
public class PrintEnvironmentVariablesModule : Module<IDictionary<string, object>>
{
protected override Task<IDictionary<string, object>?> ExecuteAsync(IModuleContext context, CancellationToken cancellationToken)
{
var environmentVariables = context.Environment.Variables.GetEnvironmentVariables()
.OrderBy(x => x.Key, StringComparer.OrdinalIgnoreCase)
.ToList();
var table = new Table
{
Border = TableBorder.Rounded,
};
table.AddColumn(new TableColumn("[bold]Name[/]").LeftAligned());
table.AddColumn(new TableColumn("[bold]Value[/]").LeftAligned());
foreach (var environmentVariable in environmentVariables)
{
table.AddRow(
Markup.Escape(environmentVariable.Key),
Markup.Escape(environmentVariable.Value));
}
((IConsoleWriter)context.Logger).Write(table);
return Task.FromResult<IDictionary<string, object>?>(
environmentVariables.ToDictionary(x => x.Key, x => (object)x.Value));
}
}