-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathGlobalCommands.cs
More file actions
50 lines (43 loc) · 1.83 KB
/
GlobalCommands.cs
File metadata and controls
50 lines (43 loc) · 1.83 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
namespace RunScript;
internal static class GlobalCommands
{
/// <summary>
/// The help command that lists all the scripts availble in the <g>global.json</g>.
/// </summary>
/// <param name="writer">The console logger instance to use.</param>
/// <param name="scripts">The project's scripts.</param>
public static void PrintAvailableScripts(IConsoleWriter writer, ScriptCollection scripts)
{
writer.Line("Available via `{0}`:", writer.ColorText(ConsoleColor.Blue, "dotnet r"));
writer.BlankLine();
foreach (var (name, script) in scripts)
{
writer.Line(" {0}", name);
writer.SecondaryLine(" {0}", script);
writer.BlankLine();
}
}
/// <summary>
/// Custom "script" that lists all available environment variables that will be available to the executing scripts.
/// </summary>
/// <param name="writer">The console logger instance to use.</param>
/// <param name="environment">The environment wrapper to use.</param>
/// <exception cref="ArgumentNullException"></exception>
public static void PrintEnvironmentVariables(IConsoleWriter writer, IEnvironment environment)
{
if (environment is null) throw new ArgumentNullException(nameof(environment));
writer.Banner("env");
foreach (var (key, value) in environmentVariables(environment).OrderBy(v => v.key, StringComparer.InvariantCulture))
{
writer.Line("{0}={1}", key, value);
}
static IEnumerable<(string key, string value)> environmentVariables(IEnvironment environment)
{
var variables = environment.GetEnvironmentVariables();
foreach (var key in variables.Keys)
{
yield return new((string)key!, (string)variables[key!]!);
}
}
}
}