-
Notifications
You must be signed in to change notification settings - Fork 468
Expand file tree
/
Copy pathCommandInfo.cs
More file actions
61 lines (47 loc) · 1.77 KB
/
CommandInfo.cs
File metadata and controls
61 lines (47 loc) · 1.77 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
51
52
53
54
55
56
57
58
59
60
61
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
// Based off of: https://github.com/dotnet/sdk/blob/e793aa4709d28cd783712df40413448250e26fea/test/Microsoft.NET.TestFramework/Commands/SdkCommandSpec.cs
using System.Diagnostics;
using Azure.Functions.Cli.Abstractions.Command;
namespace Azure.Functions.Cli.TestFramework
{
public class CommandInfo
{
public required string FileName { get; set; }
public List<string> Arguments { get; set; } = [];
public Dictionary<string, string> Environment { get; set; } = [];
public List<string> EnvironmentToRemove { get; } = [];
public required string WorkingDirectory { get; set; }
public string? TestName { get; set; }
public Command ToCommand()
{
var process = new Process()
{
StartInfo = ToProcessStartInfo()
};
return new Command(process, trimTrailingNewlines: true);
}
public ProcessStartInfo ToProcessStartInfo()
{
var psi = new ProcessStartInfo
{
FileName = FileName,
Arguments = string.Join(" ", Arguments),
UseShellExecute = false
};
foreach (KeyValuePair<string, string> kvp in Environment)
{
psi.Environment[kvp.Key] = kvp.Value;
}
foreach (string envToRemove in EnvironmentToRemove)
{
psi.Environment.Remove(envToRemove);
}
if (WorkingDirectory is not null)
{
psi.WorkingDirectory = WorkingDirectory;
}
return psi;
}
}
}