This repository was archived by the owner on Jul 18, 2024. It is now read-only.
forked from JetBrains/teamcity-csharp-interactive
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDockerCustom.cs
42 lines (38 loc) · 1.62 KB
/
DockerCustom.cs
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
// ReSharper disable UnusedMember.Global
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedType.Global
namespace HostApi;
using Internal;
/// <summary>
/// The docker custom command is used to execute any docker commands with any arguments.
/// </summary>
[Target]
public partial record DockerCustom(
// Specifies the set of command line arguments to use when starting the tool.
IEnumerable<string> Args,
// Specifies the set of environment variables that apply to this process and its child processes.
IEnumerable<(string name, string value)> Vars,
// Overrides the tool executable path.
string ExecutablePath = "",
// Specifies the working directory for the tool to be started.
string WorkingDirectory = "",
// Specifies a short name for this operation.
string ShortName = "")
{
public DockerCustom(params string[] args)
: this(args, [])
{ }
public IStartInfo GetStartInfo(IHost host)
{
if (host == null) throw new ArgumentNullException(nameof(host));
return new CommandLine(string.IsNullOrWhiteSpace(ExecutablePath) ? host.GetService<HostComponents>().DockerSettings.DockerExecutablePath : ExecutablePath)
.WithShortName(ToString())
.WithWorkingDirectory(WorkingDirectory)
.WithVars(Vars.ToArray())
.WithArgs(Args.ToArray());
}
public override string ToString() =>
string.IsNullOrWhiteSpace(ShortName)
? ((ExecutablePath == string.Empty ? "docker" : Path.GetFileNameWithoutExtension(ExecutablePath)) + " " + Args.FirstOrDefault()).TrimEnd()
: ShortName;
}